Introduction
List basics
3. Accessing list elements
Lists with if statements and loops
Lists in functions
Summary

Instruction

Excellent. Elements in a list are indexed (numbered):

List index example

And you can get a specific item from a list in the following way:

# define a list
companies = ['Royal Dutch Shell', 'BP', 'Total', 'Volkswagen', 'Glencore Xstrata', 'Gazprom']
# access Volkswagen
print(companies[3])

We provide a list name (companies), followed by a pair of square brackets. Inside, we put the index (number) of the specific element we want to retrieve. This way, we can access any element in the list.

List indices start at 0, not 1. In other words, companies[0] is the first element, and companies[3] is the fourth element. This is a common mistake among beginners, so watch out!

Exercise

What was the water level on the third day in your previously defined list? Print the right list element.

Stuck? Here's a hint!

Remember that the third element has an index of 2.