1. Add a new element to the tail of the list
Append (...)
L.append (object)--Append object to end
>>> a = [' Sam ', ' Shaw ']
>>> a.append (' 35 ')
>>> A
[' Sam ', ', ' Shaw ', ' 35 ']
2. Find The number of value in list
Count (...)
L.count (value), integer--Returnnumber of occurrences of value
>>> L = [N, ' school ', ' Ball ', 24,12]
>>> L.count (12)
2
3. to append multiple values from another sequence at the end of the list (extend the original list with a new list)
Extend (...)
>>> L =[12, ' school ', ' Ball ', 24,12]
>>> S =[' haha ', +, ' mail ']
>>> L.extend (S)
>>> L
[School ', ' Ball ', ' V ', ' haha ', ' mail ']
4. To insert the specified object into the list
Insert (Index,object)
>>> L =[12, ' school ', 12]
>>>l.insert (0, ' Shaw ')
>>> L
[' Shaw ', ' School ', 12]
5. used to remove an element from the list (the last element by default), and returns the value of the element.
Pop (...)
Description:
l.pop ([index]), item--Remove Andreturn item at index (default last). raisesindexerror If list is empty or index was out of range .
>>> L = [' Shaw ', ' School ', 12]
>>> L.pop () (the last one is deleted by default)
12
>>> L.pop (0)
' Shaw ' (delete the first one)
6. detects if the string contains substrings of str , if beg(start) and end are specified (end) scope, the check is contained within the specified range, and the method is python find () method, just as if Str not in string an exception is reported in the
Str.index (str, beg=0, End=len (String))
Parameters:
STR-- specifies the retrieved string
Beg-- start index, default to 0 .
End-- The end index, which defaults to the length of the string.
>>> L = [' Shaw ', ' School ', 12]
>>> l.index (' Shaw ')
0
>>> l.index (' Sam ')
Traceback (most recent Calllast):
File "<input>", line 1, in<module>
ValueError : ' Sam ' isnot in list
7. used to remove the first matching element of a value in the list.
L.remove (value)
Raises ValueError If the value is not present.
>>> L = [' Shaw ', ' School ', 12]
>>> L.remove (12)
>>> L
[' Shaw ', ' School ', 12]
>>> L.remove (12)
>>> L
[' Shaw ', ' School ']
8. used to reverse the elements in the list (reverse-order the elements of the list)
Reverse (...)
>>> L = [' Shaw ', ' School ']
>>> L.reverse ()
>>> L
[' School ', ' Shaw ']
9. used to sort the original list, if a parameter is specified, use the comparison function specified by the comparison function. ( sort value in list (first digit, in uppercase letters, lowercase letters))
L.sort (Cmp=none, Key=none, Reverse=false)
>>> L = [' Shaw ', ' n ', ' abc ', ' Biu ', ' CD ']
>>> L.sort ()
>>> L
[+, ' Shaw ', ' abc ', ' Biu ', ' CD ']
This article is from the "Shaw blog" blog, please be sure to keep this source http://opsedu.blog.51cto.com/9265055/1764184
Python List Method Summary