or directly on the code, looking at the code to run, see the function introduction
#Coding=utf-8#1 usage of list-listStudents = [A] a= 5Classmates= [students*2,[1,1,1,1],[1,1,1,1]]#The multiplication of the list is the linear enlargement of the arrayClassmates.append ('Test')#Add to ListClassmates.extend (students)#Iteration Extension ListPrint(Classmates.index ('Test', 2))#List Returns the first index of the developing character unknownClassmates.insert (1, 22)#List InsertClassmates.pop (2)#deletion of list itemsCLASSMATES[1] ='New Item' #Assignment of a list itemPrint(classmates)Print(Classmates[0][1])#Multidimensional Array invocation#2 The use of tuple-tuples, the values of tuples are immutableIdcode = (1000,1001,1002)#defining Multi-element tuplesName = ('Tom',)#define a single element tupleId_name = ([1000,'Tom'], (1001,'John'), 1002)#defines a multidimensional tuple, containing tuples and lists, where list points to a value that can be changed, a tuple's non -id_name[0][1]=1002Print(Id_name)#3dict-data dictionary, list is not a key, but can be used as valueSalary = {'Max': 1001,'Rachel': 20001,"Jim111": 14000}Print(salary['Max']) salary['Max'] = 2000Print(salary['Max'])Print(Salary.pop ('Jim','No Jim'))Print(Salary.get ('Rachel',-1))Print(Salary) value= []salary['Max'] =valuePrint(Salary)#4set-only key, no Value,set,dict key does not allow mutable objects, such as list, can only be string or integer these invariant objectsSet1 = Set ([All]) Set2= Set ([2, 3,'a']) Set1.add (4) Set1.remove (2) s=set (['SDF', 3])Print(Set1)Print(set1&set2,set1|Set2)Print(Set2)#Several functions sort replacedeff (x):return-Ord (x) A1= ['C','b','a']A2='SDF'b=a2.replace ('s','a') A1.sort (Key=f, reverse=False)Print("A is:"A"\na2 is:", A2,"\NB is", b)
Several data types in Python list, Tuple,dict,set use demo