Home »
Python
Python - Remove List Items
Last Updated : May 01, 2025
In Python lists, removing items can be done using methods like remove()
, pop()
, or the del
statement. In this chapter, we will learn about removing list items using these methods with the help of examples.
Removing an Item Using remove()
The remove()
method removes the first occurrence of a specific item from the list. If the item is not found, it raises a ValueError
.
Example
In this example, we are removing the city "Paris"
from the list using the remove()
method.
# Creating a list of cities
cities = ["New York", "London", "Paris", "Berlin", "Paris"]
# Removing the first occurrence of "Paris"
cities.remove("Paris")
# Displaying the updated list
print(cities)
The output of the above code would be:
['New York', 'London', 'Berlin', 'Paris']
Removing an Item Using pop()
The pop()
method removes an item at a specified index. If no index is provided, it removes the last item by default.
Example
In this example, we are removing the item at index 2
using the pop()
method.
# Creating a list of cities
cities = ["New York", "London", "Paris", "Berlin"]
# Removing the city at index 2
cities.pop(2)
# Displaying the updated list
print(cities)
The output of the above code would be:
['New York', 'London', 'Berlin']
Removing the Last Item Using pop()
When used without an index, the pop()
method removes the last item from the list.
Example
In this example, we are removing the last city in the list using pop()
with no arguments.
# Creating a list of cities
cities = ["New York", "London", "Paris", "Berlin"]
# Removing the last item
cities.pop()
# Displaying the updated list
print(cities)
The output of the above code would be:
['New York', 'London', 'Paris']
Removing an Item Using del Statement
The del
statement can be used to delete an item at a specific index or delete the entire list.
Example
In this example, we are removing the item at index 1
using the del
statement.
# Creating a list of cities
cities = ["New York", "London", "Paris", "Berlin"]
# Deleting the city at index 1
del cities[1]
# Displaying the updated list
print(cities)
The output of the above code would be:
['New York', 'Paris', 'Berlin']
Removing All Items Using clear()
The clear()
method removes all items from the list, resulting in an empty list.
Example
In this example, we are clearing all cities from the list using the clear()
method.
# Creating a list of cities
cities = ["New York", "London", "Paris", "Berlin"]
# Clearing all items from the list
cities.clear()
# Displaying the updated list
print(cities)
The output of the above code would be:
[]
Exercise
Select the correct option to complete each statement about removing items from a Python list.
- Which method removes the first matching value from a list?
- What does the
pop()
method do when called without an index?
- Which statement correctly deletes the item at index 2 from a list
my_list
?
Advertisement
Advertisement