[Python] basic grammar---4, selection statement

1.4 Select statement

To recap, the flow of the code we wrote before is basically executed from top to bottom-sequential statement

Macro view of any code is sequential statement execution

The select statement is to execute part 1 when certain conditions are met and execute part 2

# C C++ Java
if (布尔表达式) {
    部分1的代码
} else {
    部分2的代码
}
# Python
#############################
A...
if 布尔表达式 :
    B...
else :
    C...
D...
True: A-B-D
False: A-C-D
#############################
A...
if 布尔表达式 :
    B...
D...
​
True: A-B-D
False: A-D
#############################
A...
if 布尔表达式1 :
    B...
elif 布尔表达式2 :
    C...
elif 布尔表达式3 :
    D...
else :
    E...
F...
1T : A - B - F
1F 2T :A - C - F
1F 2F 3T : A - D - F
1F 2F 3F : A - E - F

Guess you like

Origin blog.csdn.net/trichloromethane/article/details/108267299