Control Flow in Python
Lessons in this section
- Conditional Statements
How to run code only when a test is true: if, else, elif chains and why their order matters, nesting, and the one-line conditional expression.
- Pattern Matching
The match statement: cases, the | pattern for grouping values, case _ as the default, the bare-name trap, and when match beats an if chain.
- Loops
Repeating work with for and while, counting with range(), break, continue and pass, nested loops, avoiding infinite loops, and the loop else.
- Functions
Writing and calling functions, every kind of argument, variable scope and the LEGB rule, packing and unpacking, annotations and docstrings.