Excellent. Elements in a list are indexed (numbered):
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!