list.remove
Remove the first item of the list that equals x.
Python 3.13
list.remove(x)Parameters
- xAny
- The value of the item to remove.
Return value
Nothing (None); the list is changed in place. Raises ValueError if the item is missing.
Examples
Removing the first match
Python 3.13
a = [1, 2, 1, 3]
a.remove(1)
print(a)[2, 1, 3]
Error for a missing item
Python 3.13
a = [1, 2]
try:
a.remove(5)
except ValueError as error:
print(error)list.remove(x): x not in list
Details
Only the first match is removed. To remove an item by index, use list.pop.
