Python 3 reference · List Methods

Python List remove() Method

Remove the first item equal to a value. Raises ValueError if the value is not in the list.

Python 3 Since 3.0

Syntax

list.remove(value)

Parameters

ParameterDescription
value The value to remove.

Return value

None.

Examples

Remove the first matchTry it yourself
pets = ["cat", "dog", "cat"]
pets.remove("cat")
print(pets)

Output

['dog', 'cat']
Remove every occurrenceTry it yourself
nums = [1, 2, 1, 3, 1]
nums = [n for n in nums if n != 1]  # remove every match
print(nums)

Output

[2, 3]

Don't remove items from a list while looping over it; build a new list with a comprehension instead.

Version history

VersionChange
Python 3.0Added