Lists

A list is a data type.

[1, 5, 7, 9]

We just wrote a list of numbers (odd numbers between 1 and 10).

Let’s say we want to retrieve the first element of the list.

l = [1, 5, 7, 9]
l[1]

The answer might surprise you. It is 5. When we want to get an element from a list we use an index.

list  1 5 7 9
index 0 1 2 3

The index always starts with 0. To get the 3rd element, we write l[3-1], meaning l[2]. To get the first element, l[1-1] meaning l[0]. To get the 100th element: l[100-1] meaning l[99]. This is how computers work: by starting from 0.