Common operations: Index, Shard, add, multiply, check whether an element belongs to a member of a sequence, length, minimum, maximum
Example:
NUMBERS=[100,34,67]
Len (numbers) #返回值为3max (numbers) #返回值为100min (numbers) #返回值为34
List :
1. List function
>>>list (' Hello ') [' H ', ' e ', ' l ', ' l ', ' O ']
* You can use join (for example: ". Join (Somelist)) to convert a list of components into a string
2, the operation of the list
Element Assignment Value:
>>>x=[1,2,3]>>>x[1]=4>>>x[1,4,3]
To delete an element:
>>>x=[' abc ', ' Def ', ' Ghi ', ' JK ']>>>del x[2]>>>x[' abc ', ' Def ', ' JK ']
Shard Assignment:
>>>x=list (' Happy ') >>>name[' H ', ' a ', ' P ', ' P ', ' Y ']>>>x[1:]=list (' ello ') >>>x[' H ', ' e ', ' l ', ' l ', ' O ']
3. List method:
Append
>>>x=[1,2,3]>>>x.append (4) >>>x[1,2,3,4]
Count
>>>x=[1,2,3,1,3,5,5]>>>x.count (3) 2
Extend
>>>a=[1,1]>>>b=[2,3]>>>a.extend (b) >>>a[1,1,2,3]
Index
>>>x=[' A ', ' B ', ' C ']>>>x.index (' B ') 1
Insert Insertion Element
>>>x=[1,2,3]>>>x.insert (2, ' a ') >>>x[1,2, ' A ', 3]
Pop removes the list element (the last one by default)
>>> x=[1,2,3,4]>>> x.pop () 4>>> x.pop (1) 2>>> x[1, 3]
Remove removes the first occurrence of a value in the list
>>> x=[' my ', ' to ', ' was ', ' she ', ' to ']>>> x.remove (' to ') >>> x[' My ', ' was ', ' she ', ' to ']
Reverse to store elements in the list in reverse
>>> x=[1,2,3]>>> x.reverse () >>> x[3, 2, 1]
>>> x=[1,2,3]>>> List (reversed (x)) [3, 2, 1]>>> x[1, 2, 3]
Sort for sorting the list at the original location
>>> x=[4,6,2,1,7,8,3]>>> x.sort () >>> x[1, 2, 3, 4, 6, 7, 8]>>> x=[4,6,2,1,7,8,3]> >> y=sorted (x) >>> x[4, 6, 2, 1, 7, 8, 3]>>> y[1, 2, 3, 4, 6, 7, 8]>>> X=[3,2,1]>>&G T Y=x>>> y.sort () >>> x[1, 2, 3]>>> y[1, 2, 3]
>>> sorted (' hello ') [' E ', ' h ', ' l ', ' l ', ' O ']
Tuples : Non-changing sequences
>>> (1, 2, 3) >>> (1, 2, 3) >>> () #空元组 () >>> 1,syntaxerror:invalid syntax& Gt;>> 1, (1,) >>> 1, #元祖必须有逗号 (1,) >>> (40+2,) (42, 42, 42)
The tuple function transforms a sequence into a narimoto group
>>> tuple ([3,2,1]) (3, 2, 1) >>> tuple (' abc ') (' A ', ' B ', ' C ')
Reasons for the non-substitution of tuples