A python conditional statement determines which block of code is executed by judging the execution result of one or more conditional statements.
The IF statement in Python is used for control program execution in the basic form:
If judging condition:
Execute statement ...
Else
Execute statement ...
#coding =utf8
A = 2
If a > 0:
print ' A greater than 0 '
Else
print ' A is less than 0 '
The judgment condition of the IF statement can be expressed by > (greater than), < (less than), = = (equals), >= (greater than or equal), <= (less than or equal).
When judging the condition for multiple values Yes, you can use if: Elif Extended form:
If judgment condition 1:
Execute Statement 1 ...
Elif Judgment Condition 2:
Execute Statement 2 ...
Elif Judgment Condition 3:
Execute Statement 3 ...
Else
Execute Statement 4 ...
#coding =utf8
name = ' C5 '
If name = = ' B6 ':
print ' This is B6 '
elif name = = ' A7 ':
print ' This is A7 '
elif name = = ' Q5 ' or name = = ' C5 ':
print ' This is Q5 '
Else
print ' This was nothing '
Note: Since Python does not support switch statements, multiple conditions can only be determined by using elif, or (or) may be used to determine if multiple conditions need to be judged at the same time, indicating that two conditions are successful when a condition is established; when using and (with), Indicates that only two conditions have been established and the conditions have been successfully
Python Foundation 6-Process Control if condition statement