Python Beginner Tutorial # 5 : Arrays

Arrays are used to store many values in one variable.

pets = ["dog","cat","fish"]

Arrays can hold many values different under the same variable name

pet1 = "fish"
pet2 = "dog"
pet3 = "dog"
pet4 = "cat"

Length of Array

Use the len() function to get the length of elements in a array.

pets = ["dog","cat","fish"]
x = len(pets)
print(x)
Output :
   3

Add elements to Array

Use the append() function to add elements to an array.

pets.append("turtle")

Remove elements from Array

Elements can be removed by using the remove() function.

pets.remove("cat")

Using loops in Arrays

Loops can be used to iterate through an array.

pets = ["dog","cat","fish","turtle","mouse"]
for x in pets:
  print(x)
Output :
dog
cat
fish
turtle
mouse
Click here for Part Six : For Loops