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_listto"Four" - Must use list index to reassign the value
Getting Started with Python
Data Types
Python Functions
Statements in Python
Basic Debugging in Python
Basic Algorithm
Object-Oriented Programming
Error Handling
Intermediate Algorithm
Python Modules