Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

list.remove

Removes the first element identical or equal to the supplied value.

Version: Python 3.14; repository image, production runtime not attested

Syntax

a.remove(value)

Removes the first element identical or equal to the supplied value.

Later equal elements stay in the list. A missing value raises ValueError.

Searches for the first identical or equal object and removes it in place. Only the leading two is removed from [2, 4, 2], leaving [4, 2], while the method call returns None. Searching for an absent value raises ValueError.

x = float("nan")
a = [x, x]
assert x != x and a.remove(x) is None and len(a) == 1 and a[0] is x

Examples

a = [2, 4, 2]
print(a.remove(2))
print(a)

Result

None
[4, 2]

Searches for the first identical or equal object and removes it in place. Only the leading two is removed from [2, 4, 2], leaving [4, 2], while the method call returns None. Searching for an absent value raises ValueError.

Sources