Array in Python

Array in Python programming is a collection of the same type of data items, which is accessed by using common name. we use two types of arrays in Python programming one-dimensional array and two-dimensional array.

Program Printing Array

Program

arr = [1, 4, 22, 43, 4, 5] #'arr' is name of Array and assigning Elements to it.
print(arr) #and printing, it printing '[1, 4, 22, 43, 4, 5]'.
Output
[1, 4, 22, 43, 4, 5]

Program Printing Array Elements

Program

arr = [1, 4, 22, 43, 4, 5] #'arr' is name of Array and assigning Elements to it.
for num in arr: #loop looping on 'arr' array Elements, and saving in 'num'.
    print(num) #and printing.
Output
1
4
22
43
4
5

Program Combine Printing Array Elements

Program

arr = [1, 2, 3] + [4, 5, 6] #'arr' is name of array and assigning Elements to it.
for num in arr: #loop looping on 'arr' Array Elements and saving in 'num'.
    print(num) #it printing '1 2 3 4 5 6'.
Output
1
2
3
4
5
6

Program Combining Two Array Elements and Printing
Program

arr = [1, 2, 3, 4] #assigning Elements to 'arr' array.
arr2 = [5, 6, 7, 8] #assigning Elements to 'arr2' array.
arr.extend(arr2) #Extending Arrays.
for num in arr:
    print(num)
Output
1
2
3
4
5
6
7
8

Program Appending Element to Array
Program

arr = [1, 2, 3]
arr.append(4) #appending 4 to 'arr' array Elements.
for val in arr:
    print(val) #it printing '1, 2, 3, 4'.
Output
1
2
3
4