The remove method
The remove method removes the specified element from the list. The method parameter specifies the element we need to remove. The method modifies the list itself. The result returned is None. Trying to remove a non-existent element will result in an exception being thrown.
Syntax
list.remove(what we want to remove)
Example
Let's remove the element 'ef' from our list using the remove method:
lst = ['ab', 'cd', 'ef', 'gh']
lst.remove('ef')
print(lst)
Result of code execution:
['ab', 'cd', 'gh']
Example
Now let's try to remove an element that is not in the list:
lst = ['ab', 'cd', 'ef', 'gh']
lst.remove('12')
print(lst)
Result of code execution:
ValueError: list.remove(x): x not in list