Remove Element from List in Python

Learn how to remove elements from a Python list using remove(), pop(), del, clear(), and list comprehension. Remove by value, index, slice, condition, duplicate values, or all items with practical examples.

Published

Updated

Read time 6 min read

Reviewed byDeepak Prasad

Remove Element from List in Python

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.

python
items = ["apple", "banana", "cherry"]

items.remove("banana")
print(items)

removed = items.pop(0)
print(removed, items)
Output

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.

python
items = ["apple", "banana", "cherry", "banana"]

items.remove("banana")
print(items)
Output

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.

python
items = [10, 20, 30, 40]

middle = items.pop(1)
last = items.pop()

print(middle, last, items)
Output

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:

python
items = [10, 20, 30]
print(items.pop(-1))
print(items)
Output

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.

python
items = [10, 20, 30, 40]

del items[2]
print(items)
Output

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.

python
items = [1, 2, 3]

items.clear()
print(items)
print(items is not None)
Output

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:

python
items = [1, 2, 3, 4, 5, 6, 7]

del items[2:5]
print(items)
Output

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:

python
items = [1, 2, 5, 4, 5, 5, 7, 5, 8]

items = [x for x in items if x != 5]
print(items)
Output

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.

python
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)
Output

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:

python
numbers = [1, 2, 3, 4, 5, 6]
numbers[:] = [n for n in numbers if n % 2 == 0]
print(numbers)
Output

Remove duplicates from a list

Preserve order with dict.fromkeys():

python
items = [1, 2, 2, 3, 1, 4]

unique = list(dict.fromkeys(items))
print(unique)
Output

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.

python
items = ["apple", "banana"]

if "cherry" in items:
    items.remove("cherry")

try:
    items.remove("cherry")
except ValueError as exc:
    print(type(exc).__name__)
Output

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.

python
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)
Output

If you need in-place removal while looping, iterate over a copy:

python
items = [1, 2, 3, 4, 5, 6]

for value in items[:]:
    if value % 2 == 1:
        items.remove(value)

print(items)
Output

Prefer the comprehension when possible.


Delete entire list vs clear list

clear() empties the list but keeps the variable:

python
items = [1, 2, 3]
items.clear()
print(items)
Output

del items deletes the variable binding:

python
items = [1, 2, 3]
del items
# print(items)  # NameError
Output

Use 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

python
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)
Output

Typical errors:

  • ValueError: list.remove(x): x not in list
  • IndexError: pop index out of range
  • NameError after del 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.


References


Frequently Asked Questions

1. How do you remove an element from a list by value in Python?

Use list.remove(value) to delete the first matching item. The method modifies the list in place and returns None.

2. What is the difference between remove() and pop() in Python?

remove() deletes by value. pop(index) deletes by index and returns the removed item. pop() without an index removes the last item.

3. When should I use del instead of pop()?

Use del when you want to delete by index or slice and do not need the removed value. Use pop() when you need the deleted item.

4. Does remove() delete all matching values?

No. remove() deletes only the first match. Use a list comprehension or loop over a copy to remove all occurrences.

5. How do you remove all items from a list?

Use list.clear() to empty the list in place while keeping the same list object.

6. Can you remove items from a list while looping over it?

Avoid modifying the same list during iteration. Build a filtered list with a comprehension or iterate over a copy instead.
Bashir Alam

Data Analyst and Machine Learning Engineer

Computer Science graduate from the University of Central Asia, currently employed as a full-time Machine Learning Engineer at uExel. His expertise lies in OCR, text extraction, data preprocessing, and …