Portal Official file Address
list. Append (x):
Add x to the tail of the list, equivalent to A[len (a):] = [x]
Cases:
>>> list1=[1,2,3,4]>>> list1.append (5)>>> list1[1, 2, 3 , 4, 5]
list. Extend (L)
-
Adds an element from list L to list, equivalent to A[len (a):] = L.
Cases:
>>> list1=[1,2,3,4]>>> l=[5,6,7,8]>>> list1.extend (L) >>> list1[1, 2, 3, 4, 5, 6, 7, 8]
- list. insert (
i ,
x )
The
-
Inserts the element at the specified location. The first parameter specifies which position to insert before the element. A.insert (0,x) is inserted at the front of the list, A.insert (Len (a), x) is equivalent to the A.append (x)
Example:
>>>list1=[1,2,3,4] >>> List1.insert (1,45) >>>
list1[ 1, 2, 3, 4]
- list. remove (
x )
-
Removes the first element of the list with a value of x, and returns error if no such element,
Example:
>>& Gt List1=[1,2,3,4,5,1,2,3,4,5 >>> List1.remove (1,2) Traceback (most recent): File <PYSHELL#80> , Line 1, in <module> List1.remove ( 1,2) Typeerror:remove () takes exactly one argument ( 2 given) >>> list1.remove (1 >>> list1[ 2, 3, 4, 5, 1, 2, 3, 4, 5]
- list. Pop ( [
i])
-
Remove the item at the given position in the list, and return it. If No index is specified, a.pop () removes and returns the last item in the list. (The square brackets around the I in the method signature denote that the parameter are optional, not so you s Hould type square brackets at that position. You'll see this notation frequently in the Python Library Reference.)
- list. Index (
x )
-
Return the index in the list of the first item whose value is x. It is a error if there is no such item.
- list. Count (
x )
-
Return the number of times x appears in the list.
- list. Sort (
cmp=none,
key=none,
reverse=false )
-
Sort the items of the list in place (the arguments can is used for sort customization, see sorted () for their E xplanation).
- list. Reverse ( )
-
Reverse The elements of the list, in place.
A example that uses most of the list methods:
List operations in Python