What PEP defines docstring conventions in Python?

The story behind the answer

PEP 257 defines conventions for Python docstrings. Its guidance covers what docstrings are, where they belong, how one-line and multi-line forms should be structured, and how documentation tools should interpret indentation.

The proposal was authored by David Goodger and Guido van Rossum and created on 29 May 2001. It describes a docstring as a string literal placed first in a module, function, class, or method definition; Python then makes it available through that object’s `__doc__` attribute.

PEP 257 is informational guidance rather than a compiler-enforced law. It recommends triple double quotes, a concise summary line, and a blank line before a longer description. PEP 8, Python’s broader style guide, points readers to PEP 257 for docstring conventions, but PEP 8 itself is not the answer to this question. PEP 484 concerns type hints, PEP 20 records the Zen of Python, and neither defines docstring conventions.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: