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

← All Python list methods · Dict methods · list vs tuple vs set