0% found this document useful (0 votes)
16 views30 pages

Arrays

The document explains the concept of arrays in Python, specifically using lists to store multiple values of the same datatype. It covers creating, accessing, and modifying arrays, including practice questions related to finding elements, adding items, and working with 2D arrays. Additionally, it discusses the use of loops for accessing elements in arrays and creating empty arrays.

Uploaded by

Anus Humayun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views30 pages

Arrays

The document explains the concept of arrays in Python, specifically using lists to store multiple values of the same datatype. It covers creating, accessing, and modifying arrays, including practice questions related to finding elements, adding items, and working with 2D arrays. Additionally, it discusses the use of loops for accessing elements in arrays and creating empty arrays.

Uploaded by

Anus Humayun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

PYTHON

9618

ARRAYS
Concept Of Arrays
5 "Pappan"

4 "Banto"
3 "Bano"

2 "Pappu"

1 "Ahmed

0 " "Taha"

Nam
Arrays stores multiple values of same
datatype in python we use list as
Arrays under single identifier
Create An Array Names
Names = ["Taha", "Ahmed", "Pappu", "Bano", "Banto", "Pappan"]

Accessing The Individual Elements


Names[0] Taha
Names[4] Banto
Names = ["Taha", "Ahmed", "Pappu", "Bano", "Banto", "Pappan"]

Print Ahmed
print(Names[1])
Finding The Length Of Arrays

Length = len(Names)
print(Length)
Print All The Elements

for x in range(len(Names)
print(Names[x])
Practice Question

Names = ["Taha", "Ahmed", "Pappu", "Bano", "Banto", "Pappan"]

Find the index position of Bano


Adding An Item In The List

Question: Add one more name in array Names

Names.append("Shabnam")
Practice Question

Input a name from the User if that


name is in array then print it is
already there and if not in the array
then add it into the array
Practice Question

Numbers = [ 10, 32, 24, 56, 75,


86]

Reverse the Order of the array

[86, 75, 56, 24, 32, 10]


Practice Question

Ask Numbers form the user and find the average of those
number and when the user types in 0 then stop asking the
number from the user and print the average

Note : 0 should not be considered a number


2 Dimensional Array
2D Array

A 2D array is a data structure that stores elements in a


grid or matrix of rows and columns. It consists of
multiple rows and columns, where each element is uniquely
identified by its row and column values. 2D arrays are
commonly used in programming to represent images,
screens and game boards
Create an Array with 5 rows and 4 Columns
0 1
2 3
0

4
Create an Array with 5 rows and 4 Columns
Practice Question

Create an Array with 3 rows and 6 Columns


How to access the individual
elements in 2D array

Array2D[RowIndex][ColumnIndex]
Accessing Elements In Loops

We use the concepts of Nested Loops to access the


individual elements

Outer loop will be for Rows and Inner Loop will be for
Columns
Practice Question

There is a 2D array print "Present if "Faisal" is in the


array
Creating Arrays Using Loops

1D Array

EmptyArray = [""] * 500


This creates a 1D array called EmptyArray with 500
elements, where each element is an empty string.
2D Array

Empty2d = [[""] * 40 for i in range(500)]

This line of code creates a 2D array with 500


rows and 40 columns with the name Empty2d
containing Empty Strings

You might also like