List Type Built-in Methods


In Table B.8, we present full descriptions and usage syntax for the list built-in methods given above.

Table B.8. List Type Built-in Methods

List Method

Operation

list.append(obj)

Adds obj to the end of list

list.count(obj)

Returns count of how many times obj occurs in list

list.extend(seq)[a]

Appends contents of seq to list

list.index(obj, i=0, j=len(list))

Returns lowest index k where list[k] == obj and i <= k < j; otherwise ValueError raised

list.insert(index, obj)

Inserts obj into list at offset index

list.pop(index=-1)[a]

Removes and returns obj at given or last index from list

list.remove(obj)

Removes object obj from list

list.reverse()

Reverses objects of list in place

list.sort(func=None, key=None, reverse=False)

Sorts list members with optional comparison function; key is a callback when extracting elements for sorting, and if reverse flag is true, then list is sorted in reverse order


[a] New in Python 1.5.2.



Core Python Programming
Core Python Programming (2nd Edition)
ISBN: 0132269937
EAN: 2147483647
Year: 2004
Pages: 334
Authors: Wesley J Chun

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net