Also known as: PEP 20, import this
The Zen of Python (PEP 20) is a collection of 19 aphorisms written by Tim Peters that capture the guiding principles of Python's design. You can read them by typing import this at the Python REPL. The aphorisms include "Beautiful is better than ugly," "Explicit is better than implicit," "Simple is better than complex," "Readability counts," and "There should be one — and preferably only one — obvious way to do it."
The Zen of Python is not a strict set of rules but a philosophical guide that shapes how the Python community thinks about language design and code style. When debating whether to add a feature or how to write an API, Python developers often invoke the Zen. For example, "Explicit is better than implicit" explains why Python requires self as a method parameter rather than making it implicit, and "Readability counts" explains why Python uses indentation for block structure.
The twentieth aphorism was intentionally left unwritten ("If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea."). The Zen of Python is one of Python's many Easter eggs — others include from __future__ import braces (which raises a SyntaxError: not a chance) and import antigravity (which opens an XKCD comic in your browser).
Discussed in:
- Chapter 1: Introduction: What Is Python? — The Zen of Python