Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

Python List Methods

Python list methods is used to perform some tasks on the lists. Python built in library has list data type which can be manipulated by using these simple method. List method is part of python reference library and available in both 2.x and 3.x versions, besides clear() and copy() method new in 3.x.

Here is the list of python list methods.

append()remove()index()reverse()
extend()pop()count()copy()
insert()clear()sort()

Use of Python List Methods

Method NameMethod Description
list.append(x)Adds a single item (element) to the end of a list.
list.extend(iterable)Extends the list by adding elements of a list.
list.insert(i, x)Inserts an element (item) to the list at a given position.
list.remove(x)Remove the first item (element) from the list whose value is x.
list.pop([i])Remove Items (elements) from the list at given position or index.
list.clear()Remove all elements from the list.
list.index(x[, start[, end]])Returns smallest index of an element in list.
list.count(x)Returns the occurrence (number of times) x appears in the list.
list.sort(key=None, reverse=False)Sort a list items and customize the sorting by using arguments.
list.reverse()Reverses the order of elements in a list.
list.copy()Returns a shallow copy of the list

 

LearnAndLearn.com © 2018 - All rights reserved