June 2017
Beginner
352 pages
8h 39m
English
Conditional statements allow us to branch execution based on the value of an expression. The form of the statement is the if keyword, followed by an expression, terminated by a colon to introduce a new block. Let's try this at the REPL:
>>> if True:
Remembering to indent four spaces within the block, we add some code to be executed if the condition is True, followed by a blank line to terminate the block:
... print("It's true!")...It's true!
At this point the block will execute, because self-evidently the condition is True. Conversely, if the condition is False, the code in the block does not execute:
>>> if False:... print("It's true!")...>>>
The expression used with the if-statement will be converted ...
Read now
Unlock full access