In our previous post, we talked about how to create and access elements in a list and in this post, we will talk about modifying elements of a list in Python.
Modify Elements of a List in Python –
To modify the elements of a list we write the name of the list followed by the index of the element that you want to change and then provide the new value that you want that item to have.
Here we have a list of company names.
In : companies Out: ['Google', 'Microsoft', 'Apple', 'Facebook', 'Netflix', 'Airbnb']
And let’s say you want to change Facebook to Twitter. To do this you will write
In : companies = 'Twitter' In : companies Out: ['Google', 'Microsoft', 'Apple', 'Twitter', 'Netflix', 'Airbnb']