Python List remove() Method

Python 列表Python Lists


Description

The remove() function is used to remove the first matching item of a value in the list.

Syntax

remove() method syntax:

list.remove(obj)

Parameters

  • obj -- object to be removed from the list.

Return Value

This method has no return value, but it removes the first match of a certain value in the list.

Example

The following example demonstrates the usage of the remove() function:

#!/usr/bin/python

aList = [123, 'xyz', 'zara', 'abc', 'xyz'];

aList.remove('xyz');
print "List : ", aList;
aList.remove('abc');
print "List : ", aList;

The output of the above example is as follows:

List :  [123, 'zara', 'abc', 'xyz']
List :  [123, 'zara', 'xyz']

Python 列表Python Lists

Other Extensions