In this Python tutorial we are going to learn the following things:
How to modify a Python List
How to add and element to a Python list
How to remove an element from a Python list
How to sort a Python list
How to find the length of a list
Now that we know the basics of Lists in Python let’s see some cool things, we can do with them.
I have created a fruits list that contains three String items. The words, “Apple”, “Orange”, “Banana”
Let's say we want to modify an item of the list. Let's say we want the third item of the list to be the word “Avocado” instead of “Banana”. How can we do that?
Simple. Remember that we have to index to help us. Banana, the third item of the list has an index of 2. So, we type:
fruits[2] = “Avocado”
With this command, we tell the computer. Go to the memory and you will find a list named fruits. Go to the slot with index 2, and replace the item that exists there with the item “Avocado”.
Watch video Lists - Add Item, Remove Item, Sort, Length - Python for Absolute Beginners Course online without registration, duration hours minute second in high quality. This video was added by user Programming With Nick 03 May 2022, don't forget to share it with your friends and acquaintances, it has been viewed on our site 331 once and liked it 21 people.