How to Remove an Item from a List in Python
If you want to remove an item from a Python list, the best method depends on what you know:
- the value of the item
- the position of the item
- whether you want to remove one match or all matches
On this page, you will learn the main ways to delete items from a list and how to avoid common mistakes.
Quick answer
items = ["apple", "banana", "orange"]
items.remove("banana")
print(items)
numbers = [10, 20, 30]
removed = numbers.pop(1)
print(numbers)
print(removed)
del numbers[0]
print(numbers)
Output:
['apple', 'orange']
[10, 30]
20
[30]
Use:
remove()to delete by valuepop()to delete by index and get the removed item backdelto delete by index or slice
What this page helps you do
This page will help you:
- Remove one item from a list
- Choose the correct method for your situation
- Avoid common errors like removing a value that is not in the list
- Understand the difference between
remove(),pop(), anddel
If you are new to lists, see Python lists explained for beginners.
Use remove() when you know the value
Use remove(value) when you know the item itself.
Important points:
remove(value)deletes the first matching item- It changes the original list
- It does not return the updated list
- Use it when you know the item, not its position
Example:
fruits = ["apple", "banana", "orange"]
fruits.remove("banana")
print(fruits)
Output:
['apple', 'orange']
remove() only removes the first match
numbers = [1, 2, 2, 3]
numbers.remove(2)
print(numbers)
Output:
[1, 2, 3]
Only the first 2 is removed.
If you want to learn more about this method, see the Python list remove() method.
remove() changes the list in place
A common beginner mistake is this:
fruits = ["apple", "banana", "orange"]
result = fruits.remove("banana")
print(result)
print(fruits)
Output:
None
['apple', 'orange']
remove() returns None. It does not create a new list.
Use pop() when you know the index
Use pop(index) when you know the position of the item.
Important points:
pop(index)removes the item at a positionpop()with no index removes the last itempop()returns the removed value- It is useful when you need the deleted item later
Example:
letters = ["a", "b", "c", "d"]
removed = letters.pop(2)
print(letters)
print(removed)
Output:
['a', 'b', 'd']
c
Remove the last item
colors = ["red", "green", "blue"]
last_color = colors.pop()
print(colors)
print(last_color)
Output:
['red', 'green']
blue
Use this when you want to remove the last item and keep its value.
For more details, see the Python list pop() method.
Use del for index or slice removal
Use del when you want to delete by position and do not need the removed item.
Important points:
del my_list[index]removes one item by positiondel my_list[start:end]removes multiple itemsdeldoes not return the removed item- It is good for deleting by location without needing a return value
Remove one item with del
items = ["pen", "pencil", "eraser"]
del items[1]
print(items)
Output:
['pen', 'eraser']
Remove multiple items with a slice
numbers = [10, 20, 30, 40, 50]
del numbers[1:4]
print(numbers)
Output:
[10, 50]
This removes the items at indexes 1, 2, and 3.
How to remove all matching items
Remember:
remove()only deletes the first match- If the same value appears many times, use another approach
- A list comprehension is often the simplest option
Example:
numbers = [1, 2, 2, 3, 2, 4]
numbers = [x for x in numbers if x != 2]
print(numbers)
Output:
[1, 3, 4]
This creates a new list that keeps only values that are not 2.
Be careful when removing inside a loop
Changing a list while looping over it can cause confusing results.
Problem example:
numbers = [2, 2, 2, 3]
for x in numbers:
if x == 2:
numbers.remove(x)
print(numbers)
Output:
[2, 3]
This does not remove every 2 because the list changes while the loop is running.
For this task, a list comprehension is usually safer and easier to read.
If you also want to clean repeated values, see how to remove duplicates from a list in Python.
What happens if the item is not found
Some list removal methods raise errors if the value or index does not exist.
remove() raises ValueError
items = ["apple", "banana", "orange"]
items.remove("grape")
This causes:
ValueError: list.remove(x): x not in list
You can avoid this by checking first:
items = ["apple", "banana", "orange"]
if "grape" in items:
items.remove("grape")
print(items)
Output:
['apple', 'banana', 'orange']
If you need help with this error, see ValueError in Python: causes and fixes.
pop() and del can raise IndexError
numbers = [10, 20, 30]
numbers.pop(5)
This causes an error because index 5 does not exist.
Safe example:
numbers = [10, 20, 30]
index = 1
if 0 <= index < len(numbers):
removed = numbers.pop(index)
print(removed)
print(numbers)
Output:
20
[10, 30]
For more help, see IndexError: list index out of range.
Which method should you use?
Use this quick guide:
- Use
remove()for value-based removal - Use
pop()for index-based removal when you also need the removed item - Use
delfor index or slice removal when you do not need a return value - Use a list comprehension to remove all matches
Here is the same idea in table form:
| Method | Removes by | Returns removed item? | Removes all matches? |
|---|---|---|---|
remove(value) | Value | No | No |
pop(index) | Index | Yes | No |
del my_list[index] | Index | No | No |
| List comprehension | Condition/value | No | Yes, if written that way |
Common mistakes
These are some common problems beginners run into:
- Using
remove()when the value is not in the list - Using
pop()with an index that is too large - Expecting
remove()to delete all matching items - Changing a list while looping over it
- Assigning the result of
remove()to a variable and gettingNone
If something is not working, these simple checks can help:
print(my_list)
print(len(my_list))
print(value in my_list)
print(index)
print(type(my_list))
These can help you answer questions like:
- Is the value really in the list?
- Is the index valid?
- Is the variable actually a list?
If you need to search before removing, see how to find an item in a list in Python.
FAQ
What is the difference between remove() and pop() in Python?
remove() deletes by value. pop() deletes by index and returns the removed item.
How do I remove the last item from a list?
Use pop() with no argument, or use del my_list[-1].
How do I remove all occurrences of a value from a list?
Use a list comprehension such as:
[x for x in my_list if x != value]
Why does remove() give an error?
It raises ValueError when the value is not present in the list.
Does remove() return a new list?
No. It changes the existing list in place and returns None.