Editor settings

General settings

Save settings

Learn to program with Python

Modify list elements #

Because Python lists are mutable, this means that once we declare a list, we can change its content. We can modify elements of a list by assigning new values to them.

For example:

my_list = ['apple', 'banana', 'cherry']
my_list[1] = 'orange'
print(my_list) # Output: ['apple', 'orange', 'cherry']

Exercise #

  • Change the value of the last element of the list my_list to "Four"
  • Must use list index to reassign the value
Output will be displayed here