Creating a list

In Python you can store values in a list. This is done using square brackets.

1
2
animals = ["horse","chicken","goat"]
daysofweek= ["Monday","Tuesday","Wednesday","Thursday","Friday"]

An empty list (with no values in) can be created as follows:

1
myList = []

We use a value in square brackets, known as an index to refer to each item of the list. For example:

1
2
3
animals[0] #would give you “horse”
animals[1] #would return “chicken”
daysofweek[2] #would return “Wednesday”

Note that in Python the first item in a list is always item 0.

Slicing a list in Python

This video clip shows how lists can be sliced in Python