The Python Language 3
Explore the main tools for control flow in Python.
We'll cover the following...
Code blocks
In C-style languages, code blocks are indicated by curly braces {...}
. In Python, we instead use a colon to introduce a code block, and all code inside that block must be indented consistently with at least one whitespace character.
Conditional execution
Like most languages, Python uses if
/ else
constructs for conditional branching. Here, we branch using the Python boolean type, which can have values True
or False
.
Press + to interact
if True: # valid code block, code indented by 4 spacesprint('Here')else:pass # pass statement does nothingif True:print('Here')pass # error: inconsistent indentation in block