预计阅读本页时间:-
General Format
The Python if statement is typical of if statements in most procedural languages. It takes the form of an if test, followed by one or more optional elif (“else if”) tests and a final optional else block. The tests and the else part each have an associated block of nested statements, indented under a header line. When the if statement runs, Python executes the block of code associated with the first test that evaluates to true, or the else block if all tests prove false. The general form of an if statement looks like this:
if <test1>: # if test
<statements1> # Associated block
elif <test2>: # Optional elifs
<statements2>
else: # Optional else
<statements3>