remove
list.remove
Removes the first occurrence of a value equal to x from the list. Raises ValueError if x is not present; returns None.
list.remove(x) Parameters
| Parameter | Purpose |
|---|---|
| x | Value to search for using equality (==), not identity (is). Only the first match is removed. |
| (no start/stop) | Unlike index, remove has no bounds — it always scans from the beginning. |
Examples
>>> lst = [1, 2, 3, 2]
>>> lst.remove(2)
>>> lst
[1, 3, 2] Removes only the first equal element.
>>> lst = [1, 2, 3]
>>> lst.remove(9)
ValueError: list.remove(x): x not in list Missing values raise ValueError — guard with `if x in lst` or try/except.
>>> lst = [1.0, 2, 3]
>>> lst.remove(1)
>>> lst
[2, 3] Uses ==, so 1 == 1.0 matches.
>>> lst = [1, 2, 3, 2, 1]
>>> while 2 in lst:
... lst.remove(2)
>>> lst
[1, 3, 1] To remove all occurrences, loop or use a list comprehension.
Gotcha
remove raises ValueError when x is absent — always check with `in` first or wrap in try/except. It only removes the FIRST match; use `[v for v in lst if v != x]` to drop all.
Related methods
list.pop
Removes and returns the item at position i (default -1, the last item). Raises IndexError on an empty list or an out-of-range index.
list.clear
Removes all items from the list in place. Equivalent to `del lst[:]`; returns None.
del list[...]
Statement that deletes the element or slice at the given position, mutating the list in place. Unlike pop() it does not return the removed value; unlike remove() it targets by index, not by value.
← All Python list methods · Dict methods · list vs tuple vs set