What is PEP 8?
PEP 8 establishes Python’s official style guide for the Python code in its standard library, codifying the principles of writing readable, maintainable Python code.
While written specifically for the Python standard library, PEP 8 has often been used as a basis for code formatting in other projects.
Key Aspects
Naming Conventions
snake_case
for functions and variablesPascalCase
for classesUPPERCASE
for constants
Whitespace Rules
- 4 spaces for indentation (no tabs)
- Two blank lines between top-level functions/classes
- One blank line between methods in classes
Line Length
- Maximum line length of 79 characters for code
- Maximum line length of 72 characters for docstrings/comments
Learn More
Last updated on