Among the many types of Data structures that Python has, there are the lists. A list in Python is a data structure made up of an ordered sequence of objects, which do not have to be of the same type.
exist many methods to work with lists, here we are going to show you some of them, if you want to learn more about lists and become a professional in Python, train with our master in Advanced Programming in Python for Big Data, Hacking and Machine Learning and stand out from the rest.
In Python lists are very flexible and it does not require that the elements of the list have to be of the same type ('int', 'float', 'chr', 'str', 'bool', 'object'), as occurs in other programming languages.
To create a list in Python, we must place all the elements that we want to add to that list between square brackets [ ] and separated by commas.
![Lists in Python 2 how to create a list in python](https://eiposgrados.com/wp-content/uploads/2021/06/listas-en-python-1.png)
Lists can contain as many items we want and as we already said, they can be of different types (integers, strings, booleans, etc.)
![Lists in Python 3 lists in python 2](https://eiposgrados.com/wp-content/uploads/2021/06/listas-en-python-2.png)
Lists can also contain other lists, which will count as a single value within the list.
![Lists in Python 4 lists in python 3](https://eiposgrados.com/wp-content/uploads/2021/06/listas-en-python-3-1024x99.png)
In order to see the created list or a specific item in the list, we can use the index, always knowing that the first element of the list occupies position 0.
![Lists in Python 5 lists in python 4](https://eiposgrados.com/wp-content/uploads/2021/06/listas-en-python-4-1024x207.png)
![Lists in Python 6 lists in python 5](https://eiposgrados.com/wp-content/uploads/2021/06/listas-en-python-5-1024x172.png)
List Methods
len()
This method returns us the length of an object, in this case when used on the list, it will return the number of data that comprises it.
![Lists in Python 7 lists in python 6](https://eiposgrados.com/wp-content/uploads/2021/06/listas-en-python-6-1024x133.png)
Index()
Returns the position of the element that we have entered for your search, if there were two identical elements, it would only return the position of the first.
![Lists in Python 8 lists in python 7](https://eiposgrados.com/wp-content/uploads/2021/06/listas-en-python-7-1024x90.png)
Append()
This method adds a element at the end of the list. In the example we see the list before and after adding the new data, in our case we have added the data “milk” and a list again.
![Lists in Python 9 lists in python 8](https://eiposgrados.com/wp-content/uploads/2021/06/listas-en-python-8-1024x234.png)
![Lists in Python 10 lists in python 9](https://eiposgrados.com/wp-content/uploads/2021/06/listas-en-python-9-1024x118.png)
Count()
With this method we can know the number of times an item is repeated in our list.
![Lists in Python 11 lists in python 10](https://eiposgrados.com/wp-content/uploads/2021/06/listas-en-python-10-1024x120.png)
Extend()
With this method we can add elements from one list to another but unlike append(), as new elements inside the new list.
![Lists in Python 12 lists in python 11](https://eiposgrados.com/wp-content/uploads/2021/06/listas-en-python-11-1024x262.png)
Remove()
With this method we can delete an item from the list indicating it as an argument. Remove() will only delete the first occurrence of the element.
![Lists in Python 13 lists in python 12](https://eiposgrados.com/wp-content/uploads/2021/06/listas-en-python-12-1024x266.png)
Insert()
With this method we can add an element to our list but unlike append(), we can insert it in the position we want within the index.
![Lists in Python 14 lists in python 13](https://eiposgrados.com/wp-content/uploads/2021/06/listas-en-python-13-1024x266.png)
Good day, can you tell me how to delete an element that is part of a list that is contained in the initial list. Thanks for your attention