Lists in Python are a linear data structure that is widely used to store data inside them. A list can store data item of any data type be it an integer, float, string, Boolean, etc.

In this article, we are going to read about methods using which we can remove items present inside a list.

We will be reading about three methods using which we can remove items from a list. One thing to keep in mind before proceeding further is that since lists are linear data structures and data is stored sequentially inside it we can use list indices to access data inside the list.

Method 1: Using remove() method

List comes with pre-defined remove() method using which we can remove a particular item from a list. We have to pass that item as an argument inside remove() method. One thing to notice is that if the same item is repeated multiple times, then only the first occurring item will be removed.

Example 1: Remove an item from a list using remove() method


List_1 = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'Feb']
print("Original list is: ", List_1)
List_1.remove('Feb') #removing item ‘Feb’ from the list
print("Altered list after removal of the item: ", List_1) 

Output:

We can see the second ‘Feb’ present at the last does not get removed.

Method 2: Using pop() method

Just like remove() method, pop() is also a pre-defined method that is supported by list and it can be used to remove items from a list. We have to pass the index of the item that we want to remove in the pop() method as an argument.

Example 2: Remove an item from a list using pop() method


List_1 = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'June']
print("Original list is: ", List_1)
List_1.pop(1) # removing item ‘Feb’ from the list
print("Altered list after removal of the item: ", List_1) 

Output:

Method 3: Using del keyword

del is a keyword in Python that can be used to delete elements in Python. We can use del keyword to remove an element from a list by specifying the index of the item that we want to remove.

 Example 3: Remove an item from a list using del keyword


List_1 = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'June']
print("Original list is: ", List_1)
del List_1[1] # removing item ‘Feb’ from the list
print("Altered list after removal of the item: ", List_1) 

Output: