Python provides several ways to remove items from a list. The right method depends on whether you want to remove by value, index, slice, condition, duplicate value, or all items. For list fundamentals, see Python list; for index-based removal with a return value, see Python list pop() examples.
Tested on: Python 3.13.3; kernel 6.14.0-37-generic.
Quick answer: remove items from a Python list
Use list.remove(value) to remove by value. Use list.pop(index) to remove by index and return the item. Use del list[index] or del list[start:end] to delete by index or slice. Use list.clear() to remove all items. Use a list comprehension to remove items by condition.
items = ["apple", "banana", "cherry"]
items.remove("banana")
print(items)
removed = items.pop(0)
print(removed, items)After remove("banana"), the list is ["apple", "cherry"]. After pop(0), removed is "apple" and the list is ["cherry"].
Python remove element from list quick reference
| Task | Use |
|---|---|
| Remove by value | items.remove(value) |
| Remove first matching value | items.remove(value) |
| Remove by index | items.pop(index) |
| Remove and get deleted item | removed = items.pop(index) |
| Remove last item | items.pop() |
| Delete by index | del items[index] |
| Delete a slice | del items[start:end] |
| Remove all items | items.clear() |
| Remove all matching values | [x for x in items if x != value] |
| Remove by condition | [x for x in items if condition] |
| Remove duplicates | list(dict.fromkeys(items)) |
| Avoid ValueError | if value in items: items.remove(value) |
Remove element from list by value using remove()
remove(value) deletes the first matching item. It modifies the list in place, returns None, and raises ValueError if the value is not found.
items = ["apple", "banana", "cherry", "banana"]
items.remove("banana")
print(items)The result is ["apple", "cherry", "banana"] because only the first "banana" is removed.
The Python list.remove documentation states that remove() deletes the first item whose value equals the given argument.
Remove item from list by index using pop()
pop(index) removes and returns the item at that index. pop() with no argument removes and returns the last item.
items = [10, 20, 30, 40]
middle = items.pop(1)
last = items.pop()
print(middle, last, items)This prints 20, then 40, leaving [10, 30]. pop() raises IndexError if the index is out of range or the list is empty.
Negative indexes work too:
items = [10, 20, 30]
print(items.pop(-1))
print(items)The last item 30 is removed.
Remove item by index using del
del items[index] deletes one item by index. It does not return the deleted value.
items = [10, 20, 30, 40]
del items[2]
print(items)The result is [10, 20, 40]. Use del when you only need deletion, not the removed item.
pop() vs del
| Method | Removes by | Returns removed item? | Best for |
|---|---|---|---|
pop(index) |
Index | Yes | Remove and use the deleted item |
del items[index] |
Index | No | Delete by index only |
del items[start:end] |
Slice | No | Delete multiple positions |
remove() vs pop() vs del
| Method | Use when | Example idea |
|---|---|---|
remove() |
You know the value | Remove "apple" |
pop() |
You know the index and need the item | Remove item at index 2 |
del |
You know the index or slice and do not need the item | Delete index 2 or slice 2:5 |
clear() |
You want an empty list | Remove all items |
| List comprehension | You want to remove by condition | Remove all odd numbers |
Remove all items from a list using clear()
clear() removes every item from the list and keeps the same list object.
items = [1, 2, 3]
items.clear()
print(items)
print(items is not None)The list becomes [], but the variable still refers to the same object. clear() returns None.
The Python docs describe clear() as removing all items, equivalent to del a[:].
Remove multiple elements from a list
Delete a slice with del:
items = [1, 2, 3, 4, 5, 6, 7]
del items[2:5]
print(items)Indices 2, 3, and 4 are removed, so the result is [1, 2, 6, 7].
For condition-based removal, use a list comprehension instead of deleting while iterating.
Remove all occurrences of a value
remove() deletes only the first match. To remove every occurrence, build a filtered list:
items = [1, 2, 5, 4, 5, 5, 7, 5, 8]
items = [x for x in items if x != 5]
print(items)The result is [1, 2, 4, 7, 8].
A while value in items: items.remove(value) loop also works, but list comprehension is usually clearer for many items.
Remove elements that match a condition
Keep the items you want and drop the rest with a comprehension.
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
words = ["", "go", "", "linux", "cloud"]
evens = [n for n in numbers if n % 2 == 0]
non_empty = [w for w in words if w]
no_none = [x for x in [1, None, 3, None, 5] if x is not None]
positive = [n for n in [-3, -1, 0, 2, 4] if n >= 0]
print(evens)
print(non_empty)
print(no_none)
print(positive)This removes odd numbers, empty strings, None values, and negative numbers by keeping what should remain. See list comprehension examples for more patterns.
To replace the original list in place:
numbers = [1, 2, 3, 4, 5, 6]
numbers[:] = [n for n in numbers if n % 2 == 0]
print(numbers)Remove duplicates from a list
Preserve order with dict.fromkeys():
items = [1, 2, 2, 3, 1, 4]
unique = list(dict.fromkeys(items))
print(unique)The result is [1, 2, 3, 4]. If order does not matter, set(items) also removes duplicates but changes order.
Remove item safely if it exists
remove() raises ValueError when the value is missing.
items = ["apple", "banana"]
if "cherry" in items:
items.remove("cherry")
try:
items.remove("cherry")
except ValueError as exc:
print(type(exc).__name__)The safe check avoids the error. The try/except pattern is useful when absence is acceptable.
Remove from list while looping
Do not modify a list while iterating over it directly. That can skip elements and cause confusing bugs.
items = [1, 2, 3, 4, 5, 6]
# Safe: build a new filtered list
items = [x for x in items if x % 2 == 0]
print(items)If you need in-place removal while looping, iterate over a copy:
items = [1, 2, 3, 4, 5, 6]
for value in items[:]:
if value % 2 == 1:
items.remove(value)
print(items)Prefer the comprehension when possible.
Delete entire list vs clear list
clear() empties the list but keeps the variable:
items = [1, 2, 3]
items.clear()
print(items)del items deletes the variable binding:
items = [1, 2, 3]
del items
# print(items) # NameErrorUse clear() when other code still references the same list object. Use del items when you want to remove the name entirely.
Common errors when removing from a list
items = [1, 2, 3]
try:
items.remove(10)
except ValueError as exc:
print("remove:", exc)
try:
items.pop(10)
except IndexError as exc:
print("pop:", exc)Typical errors:
ValueError: list.remove(x): x not in listIndexError: pop index out of rangeNameErrorafterdel list_name
Summary
Use remove() for value-based deletion. Use pop() for index-based deletion when you need the removed item. Use del for index or slice deletion when you do not. Use clear() to empty a list in place. Use list comprehension to remove items by condition or to drop all matching values.

