Last Updated: May 22, 2026
A docstring is a string literal that lives at the top of a module, class, or function. Python treats it specially: it becomes the object's __doc__ attribute and shows up when someone runs help(). Docstrings are how Python code documents itself, and they're the source most documentation tools build from. This lesson covers what PEP 257 says, the three popular docstring styles, what to put in each section, and how to keep docstrings honest as code changes.