Lists store information in Python. Not only can we use it to store an infinite amount of data but also use it in many ways like modify it and so on.
So, we can try adding two lists using the extend function.
Suppose you want to add another item in the original list, that can be done too, using the 'append' function.
Now, what if you want to add a name in between and at a certain position; at index position 1. That also can be done easily just by inserting as shown below in the screenshot.
Suppose you want to remove a name from the list.
Just do the following.
Now what to do if you want to clear the names from the list.
Simple. Add clear command and see what it does. It returns an empty list.
As you can see, the output has an empty field []
The pop function - that helps remove a single name from the list.
The last name went 'pop' as you may have noticed.
What if your list is long and you wanted to find the position of your friend but can't go through all of it. In that case, just use the command to find the index as shown below and it will output the position of your friend's name.
Remember that it starts at zero.
What if you wanted to know if your name is on the list. Then just check it using the index and you will get a message that it is not there, if it is not there of course.
I have highlighted it.
Suppose there are many people with the same name?
Just write the count command as follows.
Want to sort names in alphabetical order? Just use the sort command
Sorting numbers?
The numbers are sorted in ascending order.
Want to reverse a list?
Just input reverse and that's it.
Now for copies. Making copies of the same list is easy.
The above list functions should be practiced so as to understand how it works.
All images are screenshots of work on Colab