Conditional logic¶
Conditional logic is how Python programs make decisions — choosing between paths, reacting to input, handling the in-between cases. It looks simple on the surface (if, elif, else) but the interesting part is everything around it: what counts as true, what and and or actually return, when to reach for match/case, and how to keep nested conditions from becoming unreadable.
Start here¶
If conditionals are new to you, work through the Learn section in order — three short notebooks, around fifteen minutes each. Every code cell can be edited and run in place, directly on the page; no install required.
If you already know the basics and are looking for a specific technique, jump to the Recipes section, or scan the Reference for operators and syntax.
What this guide covers¶
Learn — if/elif/else, boolean operators and truthiness, and pattern matching with match/case.
Recipes — guard clauses, choosing between dispatch styles, and the common mistakes worth avoiding.
Reference — comparison and boolean operators, truthiness rules, and match/case syntax.
Concepts — why truthiness works the way it does, and where structural pattern matching fits.