Python List - remove method

Remove an element from a python list by specifying the value to be removed from the python list

List Updated 11 Sep 2016 1 min read

Method Name

remove

Method Signature

remove(element_in)

Method Overview

The remove() method removes the first element that matches the value specified by the parameter element_in.

Parameters

element_in:The element to be removed from the python list

Exceptions

ValueError:If the value is not in the list a ValueError is raised stating that the element specified is not in the list.

Example

python
# Example Python program that removes the first occurence of

            # an entry with a specified value from a list

# List of birds

            birds = ["Gull", "Parrot", "Peacock", "Penguin", "Robin", "Penguin"]

# Remove the birds which do not fly

            birds.remove("Penguin")

            print("Birds that can fly:%s"%birds)

Output

Output
Birds that can fly:['Gull', 'Parrot', 'Peacock', 'Robin', 'Penguin']