1. If statement:
Special note: The colon after the condition cannot be less, and must also be an English character.
Special Note:If internal statements need to have a uniform indentation, generally with 4 spaces. python replaces {} In many other programming languages in this way .
num='Ten'Print ("guess what I think?") Answer=input ()ifanswer<num: #冒号不能少 print ('too small')ifAnswer>Num:print ("too large")ifanswer==Num:print ('Equal') #tab键替代了 {} Run Result: Guess what I think? -too large
2. While statement:
The syntax is:
While condition :
Loop-Executed statements
As with if, note the colon, and note the indentation.
Example:
num='Ten'is_true=True whileTrue:answer=input ()ifanswer<Num:print ("Large") ifAnswer>Num:print ("Small") ifanswer==Num:print ("Equal") BreakOperation Result: ASmall3Smalllarge1Large0Large $SmallTenEqual
3. For statement:
For ...
For I in range (1, 101):
Print I
To explain,range (1, 101) means starting with 1 and ending with 101 (excluding 101), taking all the integers.
Example:
for in range (1,one): print (i) Run result:1234 5 6 7 8 9 Ten
Three types of patterns commonly found in Python if,while,for