Conventions and practice.
WHAT TO FOLLOW
The established style guide, applied by a formatter.
WHAT TO PREFER
Clarity over cleverness Explicit over implicit Flat over deeply nested
WHAT TO USE
Comprehensions, for transforming collections readably Context managers, for anything requiring cleanup Generators, for large sequences processed one at a time
WHY CONTEXT MANAGERS
They guarantee cleanup, even when an error occurs.
WHY GENERATORS
They avoid holding an entire sequence in memory.
WHAT TO BE CAREFUL WITH
Mutable default arguments, which are created once and shared Modifying a collection while iterating it Catching every exception indiscriminately
THAT FIRST POINT
A classic trap that surprises everyone once.
WHAT TO ANNOTATE
Function signatures, at minimum.
WHY
They document intent and enable checking.
WHAT TO ORGANISE INTO
Modules and packages, with clear responsibilities.
WHAT TO WRITE
Docstrings on anything non-obvious.
WHAT TO TEST
Behaviour, with a standard test framework.