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.
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 dimport 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.