September 2021
Beginner to intermediate
352 pages
11h 27m
English
This chapter covers the details of program structure and control flow. Topics include conditionals, looping, exceptions, and context managers.
Python programs are structured as a sequence of statements. All language features, including variable assignment, expressions, function definitions, classes, and module imports, are statements that have equal status with all other statements—meaning that any statement can be placed almost anywhere in a program (although certain statements such as return can only appear inside a function). For example, this code defines two different versions of a function inside a conditional:
if debug: def square(x): ...