Chapter 10 of 15All chapters
Chapter 10 of 15
Conditions
if, elif, else and what counts as true.
Branching
if runs a block when a condition holds, elif tests the next possibility, and else catches the rest. Comparisons chain naturally, so 0 < x < 10 reads as it looks.
- and, or and not are words rather than symbols.
- Use is only for None and other singletons, not for comparing values.
Truthiness
Empty things are false: 0, "", [], {}, set() and None. Everything else is true, so if items: is the idiomatic way to ask whether a list has anything in it.