PEP 8 (Python)

PEP 8 is the official style guide for writing Python code. It sets conventions for things like indentation, naming, spacing, and line length to keep code consistent and readable.

Python

Key recommendations include 4-space indentation, snake_case for variables and functions, CapWords for class names, and limiting lines to around 79 characters. Tools like flake8 and black help enforce it automatically.

Examples

Python

# PEP 8 style
def calculate_total(price, tax_rate):
    return price * (1 + tax_rate)

See also

Back to the Dictionary