Python next day -- if statement, pythonif statement
If statement
Computers, also known as computers, mean that computers can respond differently (Execute Code) to changes in the environment conditions (that is, expession) like the human brain) the if statement is used to control the computer to implement this function.
Syntax:
1. Single Branch, single condition judgment
If expression:
Expr_true_suite
Note: expression is the true Execution Code expr_true_sutie.
2. Single Branch, multiple condition judgment
If not active or over_itme> = 10:
Print ('Warning: service is over ')
3. if and else
If expression:
Expr_true_suite
Else:
Expr_false_suite
4. multi-branch if + elif + else
If expression1:
Expr1_true_suite
Elif expression2:
Expr2_true_suite
Elif expression3:
Expr3_true_suite
Else:
Expr_false_suite
Summary:
1. if the expression returns True after the if statement is executed, the sub-code block is executed, and the if statement ends at this end. Otherwise, the next branch is used for judgment until one of the branches is satisfied, and if
2. expression can introduce operators: not, and, or, is, is not
3. Multiple expressions should be included in parentheses to enhance readability
4. if is consistent with the else indentation level, it indicates a pair
5. Both elif and else are optional.
6. A single if statement can have at most one else, but multiple elif statements can exist.
7. else indicates the end of if judgment
8. expession can be a Boolean expression (for example, x> 1, x is not None), but also a single standard Object (for example, x = 1; if x: print ('OK '))
# A = 1 # if a: # print ('OK') # B = 1 # if B-1: # print ('OK') # if judgment can also use the expression method
9. All standard objects can be used for Boolean testing and can be compared between objects of the same type. Each object has a Boolean value of True or False. The Boolean value of Null object, any number with zero value, or Null object None is False.
The Boolean value of the following objects is False.
To be completed...