Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
List basics
8. Joining two lists
Lists with if statements and loops
Lists in functions
Summary

Instruction

Well done! We can also use the concatenation operator (+) to combine two lists.

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

# define another list
new_companies = ['E.ON', 'Eni', 'ING']

# add new_companies to the old list
companies = companies + new_companies

As you can see, we created a new list named new_companies and then added its contents to the end of the companies list. At this point, companies has the following items:

['Royal Dutch Shell', 'BP', 'Total', 'Volkswagen', 'Glencore Xstrata', 'Gazprom', 'E.ON', 'Eni', 'ING']

Exercise

Add three consecutive days using a single instruction. The water levels on days 8 through 10 were 772 cm, 770 cm, and 745 cm, respectively. Then, print the whole list.

Stuck? Here's a hint!

You can create a new list with the following three elements: [772, 770, 745]. Add both lists using +.