Skip to main content
📐
PEP 8 · Speedrun · Python 2.0 era (2001)

PEP 8 in 90 seconds — the style rules that actually matter

Most of PEP 8 is decoration. Five rules carry the weight.

PEP 8 is Python's official style guide. It's 60+ pages. In practice, code reviewers flag the same five things on 90% of pull requests, and the other 55 pages of PEP 8 are arguments at the margin. The five: naming (snake_case for vars/funcs, PascalCase for classes), 4-space indent (never tabs), 79-char-ish line length (or 100 per your team), 2 blank lines between top-level defs, and import order (stdlib first, then 3rd-party, then local).

Modern tooling enforces this automatically. `black` formats indentation + line length. `isort` sorts imports. `ruff` does both plus the rest of PEP 8 in milliseconds. The right answer in 2026 is: install ruff, never argue about style in code review again.

Before — fights every PR comment knows
import requests
import os
from .my_module import thing
def get_user_data(  userId,IncludeMeta=False ):
   if userId==None:return None
   d=requests.get(f"/api/users/{userId}").json()
   if IncludeMeta:d['meta']=os.environ.get('REGION','us')
   return d
After — PEP-8-compliant
import os

import requests

from .my_module import thing


def get_user_data(user_id, include_meta=False):
    if user_id is None:
        return None
    d = requests.get(f"/api/users/{user_id}").json()
    if include_meta:
        d["meta"] = os.environ.get("REGION", "us")
    return d

🎯 Predict the output

ruff (the modern Python linter) runs on this snippet. Predict the FIRST style violation it reports. Type the rule name (e.g. `E501`, `N806`, `E225`).

# Run ruff on the snippet below — which PEP-8 rule fires FIRST?
def get_userData(userId):
    if userId==None:return None
    d  =  fetch(userId)
    return d

# Common ruff codes to consider:
#   E225 — missing whitespace around operator (==, =)
#   E231 — missing whitespace after comma
#   E701 — multiple statements on one line (if + return)
#   E741 — ambiguous variable name
#   N802 — function name should be snake_case (get_userData)
#   N806 — variable in function should be snake_case (userId)
#   E711 — comparison to None should use is/is not, not ==

# Type the ONE code that ruff hits FIRST when scanning top-to-bottom.
Patterns from the Foundations track → cheatsheet

Or speedrun another PEP

PEP 572Assignment as an expression — 3 lines become 1.
PEP 572 in 90 seconds — the walrus that ate your for-loop
PEP 484Python stays dynamic — but you can opt into typing.
PEP 484 in 90 seconds — type hints, without TypeScript-envy
PEP 657From 'somewhere on this line' to 'this exact `[0]`'.
PEP 657 in 90 seconds — tracebacks that point at the actual sub-expression