Home >Backend Development >Python Tutorial >How to remove the value of a Python list item Python remove() method is most effective

How to remove the value of a Python list item Python remove() method is most effective

Tomorin
TomorinOriginal
2018-08-15 13:52:392341browse

In actual work, we will maintain the background, but it is unrealistic to open the background editor to retrieve and maintain it. For example, to remove the value of a Python list item, what method should be used? The most effective and speedy article, you will learn Removing the value of a Python list itemUsing the Python remove() method is the most effectiveFruit!

For Python remove () Description of method :

remove() function is used to remove the first match of a value in the list.

remove() method syntax:

list.remove(obj)

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

And because it is removing, this method has no return value

The following example shows how to use 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 results of the above examples are as follows:

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

In-class extension:

What is the difference between lists and tuples in Python? Understand the similarities and differences between tuples and lists in one article


The above is the detailed content of How to remove the value of a Python list item Python remove() method is most effective. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn