Glossary

Indentation

Indentation is Python's mechanism for defining code blocks. Where C, Java, and JavaScript use braces ({}), Python uses the level of whitespace at the start of each line. A block is introduced by a colon (after if, for, while, def, class, with, try, etc.) and consists of all subsequent lines indented to the same level. Dedenting back to the previous level ends the block.

PEP 8, Python's official style guide, mandates 4 spaces per indentation level. Tabs are allowed but should not be mixed with spaces (Python 3 raises a TabError if you do). Most editors can be configured to insert 4 spaces when you press Tab. The consistency of indentation is what makes Python code visually clean and uniform across the entire ecosystem.

Indentation-as-syntax is one of Python's most distinctive and controversial features. Proponents argue that it eliminates an entire category of formatting debates (where to put braces), ensures code looks the way it works (misleading indentation is a syntax error, not a visual trap), and forces readable code. Critics argue that whitespace sensitivity causes problems with copy-pasting, code generation, and editor misconfiguration. In practice, most Python programmers grow to appreciate it — the from __future__ import braces Easter egg (which raises SyntaxError: not a chance) reflects the community's settled view.

Related terms: Zen of Python, PEP

Discussed in:

This site is currently in Beta. Please email Chris Paton (cpaton@gmail.com) with any suggestions, questions or comments.