Introduction
List basics
7. Adding new elements to a list
Lists with if statements and loops
Lists in functions
Summary

Instruction

Nice! We can also add new elements to lists. To that end, we can use list_name.append(new_element):

# define a list
companies = ['Royal Dutch Shell', 'BP', 'Total', 'Volkswagen', 'Glencore Xstrata', 'Gazprom']

# add E.ON to list
companies.append('E.ON')

This time, E.ON will be added at the end of the list as the seventh element (with a new index of 6).

Exercise

Add the data for the eighth day to your list. The water level was 772 cm on that day. Print the list contents afterwards.

Stuck? Here's a hint!

Use water_level.append(772).