Conditionals#

Conditional statements let your program make decisions by executing different blocks of code based on whether conditions are true or false. Python's if/elif/else syntax is clean and readable, and the language also supports ternary expressions and structural pattern matching (Python 3.10+).

If/Elif/Else

Branching logic based on conditions

Use if/elif/else for conditional branching

Loops#

Loops let you repeat a block of code multiple times. Python's for loop iterates directly over sequences (lists, strings, ranges), while while loops repeat as long as a condition is true. Python also provides powerful iteration tools like enumerate(), zip(), and the itertools module.

For Loops

Iterating over sequences and iterables

For loops iterate over any iterable object