The Python Apprentice
上QQ阅读APP看书,第一时间看更新

if...else

The if-statement supports an optional else clause which goes in a block introduced by the else keyword (followed by a colon) which is indented to the same level as the if keyword. Let's start by creating (but not finishing) an if-block:

>>> h = 42
>>> if h > 50:
... print("Greater than 50")

To start the else block in this case, we just omit the indentation after the three dots:

... else:
... print("50 or smaller")
...
50 or smaller