PEP 8, section by section
The official style guide for Python code, explained rule by rule with examples: layout and line length, whitespace and blank lines, naming, imports and the programming recommendations.
- PEP 8 Explained: The Python Style Guide, Section by Section
A guided tour of PEP 8, the style guide for Python code: what each section says about layout, whitespace, comments, naming and programming recommendations, what is a rule and what is advice, and how tools enforce it.
- PEP 8 Programming Recommendations: is None, Bare except, Lambdas and Other Habits
The programming recommendations at the end of PEP 8, each with a tested example: comparing to None, truthiness, def instead of lambda, specific exceptions, small try blocks, consistent returns, startswith and isinstance.
- Python Imports Style: Order, Grouping, Absolute vs Relative and Wildcards
How PEP 8 wants imports written: one per line, at the top, grouped as standard library, third party and local; absolute versus relative imports, wildcard imports, __future__ and __all__, and sorting imports with isort or ruff.
- Python Indentation and Line Length: 4 Spaces, 79 Characters and Continuation Lines
What PEP 8 says about indentation, tabs versus spaces, the 79-character limit, continuation lines and breaking before binary operators, with tested examples and the pycodestyle codes that report each problem.
- Python Naming Conventions: Modules, Classes, Functions, Constants and Underscores
PEP 8's naming conventions explained: snake_case, CapWords and UPPER_CASE, what single and double underscores mean, names to avoid, and which linters check names (pylint, pep8-naming, ruff).
- Whitespace and Blank Lines in Python: What PEP 8 Asks For
PEP 8's rules on spaces around operators, commas, brackets, keyword arguments, inline comments and blank lines between definitions, with the pycodestyle warnings for each and the cases where the checker and the style guide disagree.





