A python conditional statement determines the code block that executes by executing the result of one or more statements (true or false). You can easily understand the execution of conditional statements by:
The Python program language specifies any non-0 and non-null (NULL) values of true,0 or NULL to FALSE. In Python programming, if statements are used in the execution of control programs, in the basic form:
if Judging Condition: Execute statement ... Else : EXECUTE statement ...
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 a condition as multiple values, you can use the following form:
Instance:
num =5 ifnum = =3: # Determines the value of num print'boss'elif Num==2: Print'User'elif Num==1: Print'worker'elif Num<0: # value is less than zero output print'Error'Else: Print'Roadman'# output when conditions are not true
Run:
Roadman # Output results
You can also use the IF condition judgment statement on the same line, as in the following example:
#!/usr/bin/-*-coding:utf-8var 100 ifvar " the value of variable var is""good bye! "
Operation Result:
var the value is 100Good bye!
Python Learning conditional statement (if loop)