Cases:
if 1=1, then it will output "Hello World" otherwise Output "Hello penphy"
Code block:
1 if Conditions: 2 Print("helloWorld")3else:4 ("Error")
Note:The indent below the if is also a space, which represents the code block below if. (Indentation is not correct, will be error)
1 if 1 = = 1 :2 print("helloWorld")3 Else:4 print ("hello penphy" )
The 1=1 condition is true, so the second line of code is executed otherwise the condition does not hold the code of line fourth
1 if1 = = 12 if2 = = 23 Print("Hello World")4 Print("Hello Seattle")5 Else:6 Print("Hello Pengfei")7 Else:8 Print("Hello penphy")
The above two graphs can be nested if else.
1INP = input ('Please enter the name of the member:')2 ifINP = ="Senior Member"3 Print('Beauty')4 elifINP = ="Platinum Member"5 Print('Sports car')6 elifINP = ="Platinum Members"7 Print('First-line actress')8 Else:9 Print('Chengguan')Ten One Print('Service Start ...')
---According to the above conditions, if you do not enter these membership words, will automatically output Chengguan
Summarize:
1. If basic statement
If condition :
Internal code block
Internal code block
Else
... #内部代码块 #
Print (' .... ')
Execute if execution condition is met
2. If support nesting
3 elif Statements
Extra supplement: Pass statement
Pass
If 1 ==1:
Pass
Else
Print (' Get out ')
Note: if 1 = = 1, then the program will skip execution
Python conditional statements and data types (i)