ScanSkill

remove

remove() function or method is used in python list to remove the first item from the list which matches the specified value.

Syntax

list.remove(object)

Here,

  • object: Required. The item to remove. If not found error is raised.

Examples

>>> list1 = [1, 2, 3, 'cloudy']
>>> list1.remove(3)
>>> list1
[1, 2, 'cloudy']
  • When no existing object is removed
>>> list1 = [1, 2, 3, 'cloudy']
>>> list1.remove('hello')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: list.remove(x): x not in list

See also

pop() and append()