First, List
Format: list = [' xxx ', ' xxx ', ' xxx ']
Properties: Can modify the contents of the list
Copy usage:
ImportCopynames= ['Yangdanhua',[' on',' to'],' Geneva','Geneva','Geneva']names01= Names#Direct ReferenceNAMES02 = copy.copy (names)#shallow copy, including NAMES02 = List[names] & names02 = names[:], the list internal values are not copiedNames03 = copy.deepcopy (names)#deep Copy, list internal values are also copied
Other common functions:
digit = [' on',' Geneva','Geneva','Geneva']digit.append ('Append')#add a string after a listPrint(digit) Digit.pop (1)#Delete the element in the list at the corresponding positionPrint(digit)delDigit[3]Print(digit)#Delete the element in the list corresponding to the positionPrint(Digit.index ('Geneva'))#position of index elementDigit.reverse ()Print(digit)#Reverses the listDigit.sort ()Print(digit)#Sort Ascending
Two, the meta-group
Format: tuple = (' xxx ', ' xxx ', ' xxx ')
Nature: immutability, non-modifiable tuple content
Common functions
A = ("',"') Tuple= ('a','BB','CCC','a','HHH')Print(Tuple.index ('a'))#Index Element LocationPrint(Tuple.count ('a'))#number of element occurrencesPrint(Tuple.__len__())#How many elementsPrint(Tuple.__add__(a))#just add the tuple to the right.
Third, the dictionary
Format: dir = {' A ': ' A ', ' B ': ' B ', ' C ': ' C '}
Properties: Variability, key to value mapping operation
You can use a dictionary to make a series of options that can be made into a three-level menu style, for example:
#Dictionary contentdir = {1:{'movie':('Action Movie','Comedy','documentary'),' Book':('Cartoon','Storybook')}, 2:{'Instrument':('Piaono','Gatar'),'Song':('Blue','Rock','Sentimental')}, 3:{'Sport':('Climb Mountains','Bungee'),' Other':('Dressing','seimming')}}#Create two variables, which will be used laterKEYS1 =[]keys2= []#Cycle JudgmentJudge ='True' whileJudge:#Print Dictionary forAinchdir: forBinchDir[a]:Print(A, b)#Input Selectioni = input ('Please input your choise:') #determine whether a number ifi.isdigit (): I=Int (i)#determine if the input is correct ifI <=len (dir) andi>=0: forKeyinchDir[i]: keys1.append (key)Print(Key)#Input Selectionj = Input ('Please input your choise:') #determine if the input is in an option ifJinchkeys1: forXinchDir[i][j]:Print(x) keys2.append (x) F= Input ('Please input your choise:') #determine if the input is in an option ifFinchKeys2:Print('Thanks for your time') Break Else: Print('Invalid input') Else: Print('Invalid input') Else: Print('Invalid input') Else: Print('Invalid input')Else: Print('Thank')Else: Print('Thank')
Four, string
Nature: Non-denatured
Examples of common methods/functions
A ='String'Print('-------String Method-------')Print(A.replace ('St',' A'))#character SubstitutionPrint(A.find ('S'))#character positionPrint(A.isdigit ())#whether it is a numeric typePrint(A.upper ())#Capitalize allPrint(A.lower ())#Change all lowercasePrint(A.split ('I'))#cut into list with I characterPrint(A.index ('T'))#Index character positionPrint(A.join ('----'))#add strings in front and back.Print(Dir (a))#you can see all the available methods
Python list/tuple/dictionary/String