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
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset