- remove
[].remove
examples/lists/remove.py
names = ['Joe', 'Kim', 'Jane', 'Bob', 'Kim'] print(names) # ['Joe', 'Kim', 'Jane', 'Bob', 'Kim'] print(names.remove('Kim')) # None print(names) # ['Joe', 'Jane', 'Bob', 'Kim'] print(names.remove('George')) # Traceback (most recent call last): # File "examples/lists/remove.py", line 9, in <module> # print(names.remove('George')) # None # ValueError: list.remove(x): x not in list
Remove first element from a list given by its value. Throws an exception if there is no such element in the list.