Keywords 1.python branch statement
- if
- else
- elif
2. The basic syntax branch
Using (1) if the
if 判断条件:
执行代码
……
Using (2) if else is
if 判断条件:
条件成立时,执行代码
……
else:
条件不成立时,执行代码
……
(3) if elif else using
if 条件1:
条件1满足时执行的代码
……
elif 条件2:
条件2满足时执行的代码
……
elif 条件3:
条件3满足时执行的代码
……
else:
以上条件都不满足时执行的代码
……
(4) Note
- python very strict code indentation, indentation as the if statement
4个空格
or aTab
key. - python code and indent together form a block of code, if the indentation is not correct, if the statement is not correct.
- python
Tab
and空格
distinguish strictly
3.if nesting
The basic syntax for nested
if 条件 1:
条件 1 满足执行的代码
……
if 条件 1 基础上的条件 2:
条件 2 满足时,执行的代码
……
# 条件 2 不满足的处理
else:
条件 2 不满足时,执行的代码
# 条件 1 不满足的处理
else:
条件1 不满足时,执行的代码
……