Lists (List Class)
Tip: All of the following methods are methods in the class, the first argument is self, and unity is not written.
The methods that are included are:
1, append (x) #将x添加到List末尾.
>>>list=[' a ']
>>>list.append (' B ')
>>>list
[' A ', ' B ']
2, Extend (L) #将表L附加到末尾, merge two lists.
>>>list=[' A ', ' B ']
>>>list2= [' C ', ' d ']
>>>list.extend (LIST2)
>>>list
[' A ', ' B ', ' C ', ' d ']
3, insert (i,x) #将元素x插入到 I this position.
>>>list.insert (0, ' test ')
[' Test ', ' a ', ' B ', ' C ', ' d ']
4, remove (x) #删除列表里第一个值为x的元素, if it does not exist, an error occurred
>>>list.remove (' test ')>>> cannot be a location
[' A ', ' B ', ' C ', ' d ']
5, Pop ([i]) #删除并返回位置为 element of I, if omitted, it means the last element stack is deleted: LIFO (LIFO)
>>> List.pop ()
' d '
>>> List
[' A ', ' B ', ' C ']
>>> List.pop (1)
' B '
>>> List
[' A ', ' C ']
6, index (i) #返回第一个值为x的元素的位置, if it does not exist, an error occurred
>>> List.index (' a ')
0
>>> list.index (' C ')
1
7, COUNT (x) #返回等于x的元素个数
>>> List
[' A ', ' C ', ' A ', ' a ', ' d ']
>>> list.count (' a ')
3
8, sort () #将List元素按照非递减排序, and a sort method is the sorted () function
>>> List.sort ()
>>> List
[' A ', ' a ', ' a ', ' C ', ' d ']
9, reverse () #将List元素反转排序
>>> List.reverse ()
>>> List
[' d ', ' C ', ' A ', ' a ', ' a ']
Next article
Dictionary (Dict Class)
This article from "A rookie on the Sky" blog, please be sure to keep this source http://rmeos.blog.51cto.com/761575/1710207
Python Basics (List Class)