7.1 if 语句 The if statement

The if statement is used for conditional execution:

if 语句用于条件性执行:

if_stmt  ::=  "if" expression ":" suite
    ( "elif" expression ":" suite )*
    ["else" ":" suite]
Download entire grammar as text.

It selects exactly one of the suites by evaluating the expressions one by one until one is found to be true (see section 5.10 for the definition of true and false); then that suite is executed (and no other part of the if statement is executed or evaluated). If all expressions are false, the suite of the else clause, if present, is executed.

它对表达式逐个求值, 直到其中一个为真时, 准确地选择相应的一个语句序列.(对于真和假的定义参见5.10节); 然后该执行语句序列(if语句的其它部分不会被执行和计算).如果所有表达式都为假, 并且给出了else子句,那么将执行它包括的语句序列.