1. About the Python program execution principle:
?? Create a new Python file named auth.py, and then invoke the file from another Python file.
Python Run Process:
Python first compiles the code (. py file) into a bytecode-pyc file that can be read by the interpreter, so that it can be handed over to the bytecode virtual machine, one to execute the bytecode instruction, to complete the execution of the program.
When the module is loaded, if both. py and. Pyc,python try to use. PYC, if the. PYc is compiled earlier than the. Py modification time, recompile the. py and update. PYc.
2. data type:
First, you can see the data type by type (): int? Long? Float?
Common data types:
integer: Integers have different value ranges in different bit systems floating point number (float): Can be roughly understood as a decimal complex: plural
Boolean value: TRUE or false:only possible values (1,0) e.g 0 = = false-> true
String: Contact more, such as a = "store", "store" is a string.
3. Very useful----> list!! List
How do I save a set of data?
The first way (but the efficiency is a bit low):
" A,b,c " "A","B","C "
So invented the second way: list (called array in other languages)
Age = 9= ["A","B","C " ", 22,age]
Each intermediate value is called an element, and a variable or number can be stored.
Slicing method:
name [# Take the second # to the penultimate # Take the first to the second, can also write [: 2]# actually not the last one, but # you can take the last one . # can always fetch a letter to a string
To change the list:
NAME[1] ="R" #element Assignment ValueName.insert (2,"RR")#inserting elementsName.append ("Alex")#AppendName.remove ("A")#Delete del name[4:6] Delete len (name)Name.pop ()#deletes an element in the list, and returns the position of the element in the ()Name.reverse ()#Reverse List Order
Determine if there is an element in the list:
name = [8,6,9,4,6,8,1]if in name: print("9 are in Name")
Determine if there is any element in the list, and if so, find its location:
name = [8,6,9,4,6,8,1]
If 9 in Name:
Ele = Name.count (9)
Position_of_ele = Name.index (9)
Print (Position_of_ele)
Replace the position of element 9 in the list with 9999:
name = [8,6,9,4,6,8,1] for in range (Name.index (9)): = 9999
The small list is appended to the large list (the small list also exists) and expands into a new list:
name = [8,6,9,4,6,8,1]
name2 = [2,4,6,7]
name.extend (name2)
List Adjustment Example:
#definition ListGROUP11 = ["QQ","ww","ee","RR","TT","GG","hh","nn","mm","ZZ","SS","BB","AA"]group11.insert (5,"xx")#Add "XX" to the 5 position in the listGroup11.insert (6,"yy")#add "yy" to the 6 position in the listDF = Group11[2:8]#take 3–7 's nameGroup11.remove ("xx")#Remove XX from the listGroup11.remove ("yy")#Remove yy from the listgroup11[-4]="Group leader ZZ" #add comments to the leaderPrint(Group11[0:-1:2])#print one from the first to the lastPrint(Group11[::3])#Print one from the beginning to the end of every two
Tuple tuples : same as list, but cannot be changed after generation, read-only list. e.g T = (a)
4. About strings:
Names ="Bee,honey,ss"name2= Names.split (",")#remove comma from namesPrint("|". Join (NAME2))#The elements are combined, and the middle is separated by |name="Honey"Print(" "inchName#The result is false, because there are no spaces in namePrint(Name.capitalize ())#capitalize the first letterPrint(Name.center (40,"-"))#-------------name-------------(40-)Print(Name.find ("E"))#find the location of e
Judging is not a number:
Age = input (' age:')if age.isdigit (): = int (age) Else: print("Invalid numbers")
5. Dictionary dictionary
DIC = { 1:{"name":"Hanmeimei"," Age": 25,"Gender":"F"}, 2:{"name":"Lilei"," Age": 23,"Gender":"M"}}Print(Dic[1])#Print the value of 1 in DICPrint(dic[1][" Age"])#Print the value of age corresponding to 1 in DICPrint(Dic.values ())#Print the value of the head keys in DICPrint(Dic.items ())#Print all elements in dicPrint(Dic.keys ())#Print the head keys in DICQ= Dic.setdefault (3,"Hahahahha")#enter a key, and return a default value if nonePrint(q) forKeyinchDIC:Print(Key,dic[key])#print key and value separately
6. While Loop
Count =0 whileTrue:count+ = 1ifCount > 50 andCount < 60:#Loop 50-60 times Continue Continue Print("yayayayayayayay!", count)#Print a string ifCount = = 100: Print("nonononono!") Break #count to 100 print different strings, jump out of the loop
7. Computer representation, storage unit:
The smallest unit that the computer could represent is bits
The smallest unit of memory stored by a computer is bits (bit)
8bit = 1byte (bytes)
1024bit = 1kbyte
1024kbyte = 1mbyte
Python Notes Summary Week2