Python List remove(x) Method
Python remove() method removes the first item from the list which is equal to the passed value. It throws an error if the item is not present in the list. Signature and examples are described below.
x : Element to be deleted.
It does not return any value rather modifies the list.
Let's see some examples of remove() method to understand it's functionality.
Python List remove() Method Example 1
A simple example in which we are removing an element from the list.
1 2 3 After removing: 1 3
Python List remove() Method Example 2
If list contains duplicate elements, the method will remove only first occurred element. See the example below.
1 2 3 2 After removing: 1 3 2
Python List remove() Method Example 3
If we remove an element which is not found in the list, it throws an error to the console. See the example below.
ValueError: list.remove(x): x not in list 1 2 3 2
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week