1. Data type
1 first, basic use 2 1. Use 3 2. Definition method 4 3. Common operation + built-in method 5 c12> Ii. Summary of the type of change 6 1. Save a value or save multiple values 7 2. You can have multiple values, and what type of value can be 8 3. Unordered order 9 4. Variable or immutable : value changed, id unchanged, variable = = do not hash one by one immutable: value change, ID is changed, immutable = can hash
1 Three, String2Name=' MySQL '3 #Limited Mastery of the operation:4 #value by index (positive fetch and reverse fetch): can only take5 Print(Name[0])#Positive Fetch6 Print(Name[-2])#Reverse Fetch7 #slicing (Gu Tou regardless of tail, step)8 Print(Name[1:3])9 Print(Name[1:4:2]) 2 is the step sizeTen Print(name[Start: End: Step]) One Print(Name[6::-1])#Understand A #length Len -Name ='MSYQL' - Print(len (name)) the Print('my' inchname) - #Remove blank strip (default minus space) -Passwoed='xu19920615' -Passwoed=Passwoed.strip () + Print(passwoed) - #Remove Other characters +Name='***mysql****' AName=name.strip ('*') at Print(name) - #splitting split -User='Roo:0:0:0:/usr/bin/bash' -User=user.split (':') - Print(user) - in Name.lstrip () only remove left - Name.rstrip () only remove right to Name.find () finds a string, looks from left to right, and returns the index of the first character if there is one +If not returned-1 - Name.index () character index position, if no error the Name.count () Statistics string format * #Join $ Print(':'. Join (name))Panax Notoginseng #Judging numbers -Num1=b'4' theNum2=u'4' +num3='Four' Anum4='④' theNum1.isdigit () Determine if it is a number (can only Judge Bytes,unicode)
1 Iv. List2 list ()3 #Priority operations:4 #Access Values by index (positive fetch and reverse fetch)5name=['MySQL','Root','name']6name[0]='Xuchenyang'7 #slices8Name[0:2]9 #lengthTen Len (name) One #member Operation in A #Append -Name.append ('MySQL') - #Delete (simple delete, does not return output value, and is deleted by value) theName.remove ('MySQL') - #Delete by index, default from the end (you can remove the deleted value) -res = Name.pop ()#You can enter only the index number inside the parentheses, cannot enter the string directly -Name.insert (0,'Alex')#Insert a value in front of the first value +Name.extend ([1,2,3,4,5])#Insert a list in the form of a list -Name.count ()#Statistics +Name.clear ()#Clear List AName.sort ()#Sort
1 v. tuples 2 # action: Save multiple values , the tuple is immutable (a key that can be used as a dictionary) in comparison to the list, primarily to read 3 # precedence: 4 value by index (positive fetch + reverse): can only take 5 slice (Gu Tou regardless of tail, step) 6 length 7 member operations in and not in 8 name= (1,2,3,4,5 9 name.count () statistics 10 Name.index () Index
1 VI. Dictionary2 #definition: Key must be immutable type, value can be any type, list cannot be a dictionary key3 #Priority operations:4 Access Value by key: can be stored as desirable5Name = {'name': 12,'MySQL': 14,'Root': 13}6name['name']# A7 length Len8Member operations in and notinch9 operation of KeyTen Delete OneName.pop ('name2222','No')#If there is no value, it returns no A Key keys () , value values (), key value pairs items () - Other: -Name.get ('name212')#Not found, no error, return none theName.popitem ()#Delete a key value pair - Name.fromhex () -QQ = {'QQ': 12} -Name.update (QQ)#update dictionaries, no additions, there are modifications +Name.setdefault ()#if a key already exists in the field, it is not modified, the value is returned, no is added, and the new value is returned.
1 Seven, add two methods of assignment: 2 1. Chain Assignment 3 x=y=z=10 4 2. Extract the value we want from a data type 5 m=10 6 N =20 7 m,n=n,m 8 name = (1,2,3,4,5) 9 x,y,z,a,b=name c15>10# only X, bprint (x,b)
1 Eight, set2 set ()3 #role: de-weight, relational operations4 #Defining Collections5 #A collection can contain multiple elements, separated by commas6 #the elements of a collection follow three principles:71: Each element must be an immutable type (hash, which can be used as a dictionary key)82: No duplicate elements93: UnorderedTen #Priority operations: One length Len AMember operations in and notinch -|Collection -s={1,2,3} thes1={1,2,3,4,5,6} - Print(S |S1) -&the intersection takes out the repeating part - Print(S &S1) +-the difference set takes out the S1 part of s inside, outputs the remainder - Print(S-S1) +^symmetric difference sets take a part other than common A Print(s ^S1) at== ->,>=, <,<=parent set, subset - and set - Print(S.union (S1)) -S1.pop ()#randomly Delete and return deleted results -S1.add ()#Add Value inS1.discard ()#Delete specified value, no error, no return value -S1.remove ()#Delete The specified value, simply delete, will not return the result of deletion, if not exist on the error toS1.isdisjoint ()#returns True if S and S1 have no intersection + forCycle
Python Day 2