Python is the only major language where formatting is syntax — wrong indentation is a crash, not a style violation. That makes clean formatting not just aesthetic but functional.
The rules that matter daily
- 4 spaces per indentation level — the community standard (PEP 8). Tabs work but mixing them with spaces breaks the parser.
- Blank lines: two before top-level functions and classes, one inside them. It’s how Python code “breathes.”
- Line length: 79 characters by convention, 88 or 100 accepted in practice — long lines are the most common style complaint in reviews.
- Spaces around operators:
x = 1, notx=1; butf(a, b)with no spaces inside parentheses. - Snake_case for functions and variables,
CamelCasefor classes,UPPER_CASEfor constants.
Why formatted code matters here more
In Python, poorly formatted code is genuinely harder to debug — indentation is the block structure. A missing or extra level changes what the program does, and formatting tools catch it instantly.
Formatting
- Paste your code into the Python formatter.
- The tool normalizes indentation, spacing, and line breaks to the standard style.
- Copy the result — and run it, because formatting should never change behavior, and confirming that is the whole point.
The honest note
A formatter applies rules; it doesn’t fix logic. If the code was broken, it’s still broken — now prettily. But formatted code makes the bugs visible, which is half the job of debugging.
Consistency is the actual goal: any team that formats identically spends zero review time on style, and all of it on substance.