Python List Remove Method

title: List Remove Method

List Remove Method

The remove() method removes the argument given to it from the list.

Example Usage

words = ["I", "love", "Python"] words.remove("I") print(words)



Note that it returns an error if the element to be removed is not found in the list as illustrated in the example below.

kiss = ["keep", "it", "simple", "stupid"] kiss.remove("complex") print(kiss)


Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: list.remove(x): x not in list

If there are duplicate elements in the list, the remove() function removes the first occurrence of the element.

numbers=[1,2,3,4,5,1,6] numbers.remove(1) print(numbers)



More Information:

More information about remove() can be found here

This article needs improvement. You can help improve this article. You can also write similar articles and help the community.