There are many methods for the list type. here, there are many methods for listing all methods of the list type. here, all methods of the list type are:
List. append (x)
Add an element to the end of the list, which is equivalent to a [len (a):] = [x].
List. extend (L)
Add all elements in a given list to another list, which is equivalent to a [len (a):] = L.
List. insert (I, x)
Insert an element at the specified position. The first parameter is the index of the element to be inserted before it, for example,. insert (0, x) is inserted before the entire list, and. insert (len (a), x) is equivalent to. append (x ).
List. remove (x)
Delete the first element whose value is x in the list. If no such element exists, an error is returned.
List. pop ([I])
Delete an element from the specified position in the list and return it. If no index is specified, a. pop () returns the last element. The element is deleted from the list. (Square brackets on both sides of method I indicate that this parameter is optional, rather than requiring you to enter a pair of square brackets. you will often encounter this mark in the Python library reference manual .)
List. index (x)
Returns the index of the first x element in the list. If no matching element exists, an error is returned.
List. count (x)
Returns the number of times x appears in the list.
List. sort ()
Sort the elements in the list in place.
List. reverse ()
The elements in the reverse list.
The following example demonstrates most of the methods in the list.
>>> a = [66.25, 333, 333, 1, 1234.5]>>> print a.count(333), a.count(66.25), a.count('x')2 1 0>>> a.insert(2, -1)>>> a.append(333)>>> a[66.25, 333, -1, 333, 1, 1234.5, 333]>>> a.index(333)1>>> a.remove(333)>>> a[66.25, -1, 333, 1, 1234.5, 333]>>> a.reverse()>>> a[333, 1234.5, 1, 333, -1, 66.25]>>> a.sort()>>> a[-1, 1, 66.25, 333, 333, 1234.5]