Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

[].remove

  • remove
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.