3.2.3 - List methods

Lists are mutable objects. This means that we can change a list, add or remove items find the minimun and the maximun or even add one list items to another list.

You can learn more about lists here https://docs.python.org/3/tutorial/introduction.html#lists

and you can find some of the list methods here https://docs.python.org/3/tutorial/datastructures.html#more-on-lists 

We will start creating a list an empty list :

>>> new_list=[]

After that we can add items using the append command :

>>> new_list.append(13)

And we can add a range of numbers :

>>> for i in range(1,21):
        new_list.append(i)

We can view the list and its contents in the variable view of Thonny. We can also view the list with the command :

>>> new_list

If we want to count the instances of an item inside the list we can use the method count :

>>> new_list.count(13)

If we want to remove an item we can use the remove method to remove the first instance of an item :

>>> new_list.remove(10)

>>> new_list.remove(13) # removes only the first 13

We can sort the list in normal (ascending) order :

>>> new_list.sort()

and we can sort it in reverse order (descending) :

>>> new_list.reverse()

We can also find the position of an item :

>>> new_list.index(18)

Finally we can find the maximun and minimum of a list :

>>> max(new_list)

>>> min(new_list)

and we can add the items of a list :

>>> sum(new_list)

and many more that you can search in the links above.