Conditions and Iteration
Write clear branches, for loops, ranges, enumeration, and guard clauses.
Programs become useful when they can choose what to do and repeat work reliably. Python gives you a small set of control-flow tools for that job: if, elif, and else select a branch; for visits each item in an iterable; while repeats while a condition remains true; and enumerate gives you a position without managing a counter yourself.
Choose a path with conditions
A condition is an expression that produces True or False. Use if for the first case, elif for mutually exclusive alternatives, and else for the remaining cases. Put the most specific or important rules where a reader can see them, and keep each branch small enough to explain.
Python compares values with operators such as ==, !=, <, <=, >, and >=. Use and and or to combine conditions, and use not when you need the opposite. Parentheses are often worthwhile when they make the intended grouping obvious.
Understand truthiness
Python treats some values as false in a condition: None, False, numeric zero, and empty collections or strings. Most other values are true. This is convenient for optional data, but do not use a truthiness shortcut when zero, an empty string, or an empty collection is a valid value that needs its own meaning.