How to remove an item from a list in Python

To delete an element from the list in the python language you can use the function del

del lista[indice]

The pop method is used to extract and delete an element from the list


To remove all items with a certain value from the list


Deleting elements from a list involves moving and changing the index number of subsequent elements. Therefore, the operation has complexity O(n).


Example 1 ( del )

Given the following list:


To eliminate the second element with the method del.

del lista[0]

The first element of the list has index zero, the second has index one, etc.

After the operation the list is

['B', 'C', 'D', 'E', 'F']

Now, the first element of the list is 'B'.

Example 2 ( pop )

To extract and delete the second element of the list


The pop method extracts the second element of the list ('C') and assigns it to the variable x. Then remove the item from the list.

Now, the list is

['B', 'D', 'E', 'F']

Example 3 ( remove )

To delete items in the list that have the value 'E'


Now, the list is

['B', 'D', 'F']

Example 4 ( range )

To delete the first two elements of the list:

del lista[0:2]

The function removes the elements from position 0 to position 2 excluded.

Now, the list is


There is only the F element in the list


Report us an error or send a suggestion to improve this page

Python List