Python list remove method – how to delete elements from list

Remove method to remove objects from list

The remove() method is used to remove an object or element from list. If there are multiple occurrences of object specified in remove() method then only first object/element will be removed.

 

Syntax of remove() method

List_name.remove(object/element)

Where object or element is the list item to be removed from the list.

 

Example of using remove() method

In example below a list is created with mixed numbers and strings. We will use list remove method and remove numbers one by one and then print the final list.

 

 

Output will be:

[1, ‘this’, 2, ‘is’, 3, ‘list’, 4, ‘chapter’]

[‘this’, ‘is’, ‘list’, ‘chapter’]

 

Using del statement to remove elements

If you exactly know the order of list then del statement can be used to remove element from list as below. Just to remind index of list start from 0.

 

Example of using del method

 

 

Output will be

List before delete: [‘this’, ‘is’, ‘list’, ‘chapter’]

List after delete: [‘is’, ‘list’, ‘chapter’]