Python List remove() Method (original) (raw)

Last Updated : 01 May, 2025

Python list remove() function removes the first occurrence of a given item from list. It make changes to the current list. It only takes one argument, element we want to remove and if that element is not present in the list, it gives **ValueError.

**Example:

Python `

a = ['a', 'b', 'c'] a.remove("b") print(a)

`

**Explanation:

Syntax of remove() method

list_name.remove(obj)

**Parameter:

**Return Type: The method does not return any value but removes the given object from the list.

**Exception: If the element doesn’t exist, it throws ValueError: list.remove(x): x not in list exception.

Examples of remove() method

1. Passing list as argument in remove()

If we want to remove multiple elements from a list, we can do this by iterating through the second list and using the remove() method for each of its elements.

Python `

a = [1, 2, 3, 4, 5, 6, 7, 8] b = [2, 4, 6]

for item in b: if item in a: a.remove(item)

print(a)

`

**Explanation:

2. Trying to delete Element that doesn’t Exist

In this example, we are removing the element ‘e’ which does not exist in the list which will result in a ValueError. We can use a try except block to handle these exceptions.

Python `

a = [ 'a', 'b', 'c', 'd' ]

a.remove('e') print(a)

`

**Output:

Traceback (most recent call last):
File “Solution.py”, line 4, in
a.remove(‘e’)
ValueError: list.remove(x): x not in list

**Explanation:

**Related Articles:

Similar Reads