1. List
List common features include: Append, remove, insert, index, sort, reverse, pop
a=['a','b','C', 123]Print(a)Print(Type (a)) A.append ('ASDASDASD')#Add a StringPrint(a)Print(A.index (123))#query, similar to the Find functionA.insert (1,'AISI')#inserts a character before the specified indexPrint(a) a.pop ()#removes the element at the specified index location, without specifying the return and delete the lastPrint(a) a.remove ('b')Print(a) a.append ('Aisirea') A.sort ()#SortPrint(a) a.reverse ()#reverse OrderPrint(a)Print(a[3:])Print(A[1:4])#slices (last count minus 1)Print(A[1:4:2])#the last one is the interval numberList
2, meta-group
Tuples are defined by parentheses and can store some immutable values, unless the tuple is redefined, and the common operations of tuples include count, index
str1='jdsjlasjajkdasjksdjkadsjkdasajksd231'Print(Tuple (STR1)) a=('AI')Print(Type (a)) b=('AISI',)Print(type (b))#When using tuble Note: Add a comma after a single tuble element, otherwise the parser will not recognize the tuple type#method of Tuple: Count indexTu1= ('a','b','C','Q','a','C')Print(Tu1.count ('b'))#count is used to count the number of elementsPrint(Tu1.index ('Q'))#Index returns subscript (there is no element times error)Ganso
3. Dictionaries
The dictionary is the only key_value,value value in Python that is mutable and the key value is unique
Common methods for dictionaries include keys, values, GET, SetDefault, Iteritems, Pop, Fromkeys, update
1k={'name':'Hzd',' Age': 20,'Sex':'Mans'}2 Print(k)3 Print(Type (k))4K1=dict (a=1,b=2,c=4)5 Print(K1)6 #k1.clear ()7 #print (k1)8 #Clear9 Print(K.get (' Age'))Ten #get returns the value of the specified key One Print(K.setdefault ('name')) A Print(K.setdefault ('Address','Diqiu')) - #SetDefault Returns a value if there is a value, returns null if it is not, or assigns it to the dictionary - Print(K.keys ()) the #keys get keys - Print(K.values ()) - #Values Get value - Print(K.iteritems ()) + #Iteritems getting Objects - + forA, binchK.iteritems (): A Print(A, b) at Print(K.items ()) - Print(k) -K.pop ('Address') - Print(k) - #Pop Delete specified location -l=['a','D','b','Q'] inm={} -N=m.fromkeys (l,123) to Print(n) + #get the value from the list -l1=['a','W','D','e'] thel2=[1,2,3,4] *dict_test=dict (Zip (l1,l2)) $ #The zip function is used to overlayPanax Notoginseng Print(dict_test) - dict_test.update (k) the Print(dict_test) + #Merge and overlay a dictionary AMm=dict (a=1,b=3,c=5,d=2) the PrintSorted (Mm.iteritems (), key=LambdaD:d[1],reverse=True) + #sort operation, true reverse order, false positive orderDictionary
Python data type (bottom)