Python Language / Python Arrays

It is collection of similar data items stored at contiguous memory locations and access with a single variable name. Python does not have built-in support for Arrays, but Python Lists can be used instead.

Sample Programs
Program Output
# create and access elements of an array.
Fruits= ["Apple", " mangoe", " apricot"]
print(Fruits[0])
print(Fruits[1])
print(Fruits[2])
print(Fruits)
Apple
 mangoe
 apricot
['Apple', ' mangoe', ' apricot']
 #find number of elements of an Array
Fruits= ["Apple", " mangoe", " apricot"]
x = len(Fruits)
3
#Looping Array Elements
Fruits= ["Apple", " mangoe", " apricot"]
for x  in Fruits:
print(x)
Apple
Mangoe
Apricot
# Adding Array Elements using append()
Fruits= ["Apple", " mangoe", " apricot"]
Fruits.append("oranges ")
for x  in Fruits:
print(x)
Apple
Mangoe
apricot
oranges
# Removing Array Elements using pop method
Fruits= ["Apple", " mangoe", " apricot"]
Fruits. pop(1)
for x  in Fruits:
print(x)
Mangoe
apricot
# Removing Array Elements using remove method(first occurrence of specified value)
Fruits= ["Apple", " mangoe", " apricot"]
Fruits. remove("Apple")
for x  in Fruits:
print(x)
Mangoe
apricot


Home     Back