Cycle:
1.While Cycle
While condition:
? ? ? ? ? Statement
Eg: Quit after retrying 3 errors
Count?=?0_number=15while?count?<3:???? Guess_age?=?int (Input ("Guess?age:"))???? If?? Guess_age?==_number:???????? Print ("Yes")???????? Break???? Elif?? Guess_age?>?_number:???????? Print ("Think? Smaller ")???? else:????? Print ("Think? Bigger ")????? Count+=1else??:???? Print ("Too? Many? Times ")
2.For Cycle
Continue is returned to the beginning of the loop
For I in range ("lower limit, upper limit, step Size"):
EXECUTE statement
Eg: program optimization, add judgment input after count=count+1
If?count?==?3:??? Try?=input ("Do?you?want?to?try?")??? if?try?! = "N"??? Count=0
Module:
1. Mainly divided into standard library and third-party library (need to download and install)
2. Import library name and file name not the same
General standard library Path: Python_path----base----Lib
The third party libraries path: ... Lib---site-packages
SYS module-->import SYS
Sys.path:Python Environment variables
SYS.ARGV: Relative path
OS module: Import os
Os.system: Call system cmd, result output directly on screen, cannot save
Os.popen: Call system command to save
eg
Cmd_res=os.popen ("dir"). Read () print ("--", cmd_res)
Os.mkdir: Creating a Directory
eg
Os.mkdir ("New dir")
You can write your own module in the directory or environment variables to facilitate other program calls
PYc
Python, like Java, is a compiled and interpreted language. When the program runs, the results will be saved in the PYc file, and when the second program runs, it will first look for the existence of the PYc file, if there is no need to compile direct interpretation, improve efficiency.
Python basics-Loops and modules