Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Displaying values
Variables
The print function
List basics
20. Assigning new values
Summary

Instruction

Good. Using square brackets, we can also assign new values to specific elements.

# define a list
canadian_cities = [
    'Toronto', 'Montreal', 'Calgary', 'Ottawa',
    'Edmonton', 'Mississauga', 'Winnipeg', 'Vancouver', 
    'Brampton', 'Familton']

# population changes...
canadian_cities[9] = 'Quebec'

We found out that Quebec now has more people than Familton, so we change the tenth element (remember, its index is 9) to 'Quebec'. Familton is out of the game!

Exercise

Correct the mistake in your data. The third day's sales should be 3023.

Stuck? Here's a hint!

The third day has index 2.