For conditional branching:
ifE0:B0elifE1:B1elif ... else:Bf
This is the most general form, and means: if
expression is
true, execute block E0; otherwise, if
B0 is
true, execute block
E1; and
so forth. If all the conditions are false, execute
B1.Bf
The elif clause is optional,
and there can be any number of them. The else
clause is also optional.
When evaluating whether an expression is true or
false, false values include None, a
number equal to zero, an empty sequence, or an empty
dictionary. All other values are true.
Here's an example:
if x < 0:
print "But it's negative!"
else:
print "The square root of", x, "is", x**0.5