A docstring is a string that occurs as the first statement in a module, function, class, or method definition, and is used to document the object in which it occurs.
A docstring is a string that occurs as the first statement in a module, function, class, or method definition, and is used to document the object in which it occurs.
For example, this Python module:
"""shibboleth.py - answer a common interview question with style and grace."""
DEFAULTS = (
(3, "Fizz"),
(5, "Buzz"),
)
def fizzbuzz(limit=15, sep=" ", **kwargs):
"""Print from 1 to `limit`, replacing as in the childhood game."""
transform = sorted((v, k) for k, v in kwargs.items()) or DEFAULTS
for number in range(1, limit + 1):
matches = (word for factor, word in transform if number % factor == 0)
print(sep.join(matches) or number)
... contains two docstrings: a module-level docstring which contains the filename of the module and a brief description of its purpose, and a function-level docstring which describes the behaviour of the function in which it occurs.
Conventions for writing Python docstrings can be found in PEP 257: Docstring Conventions.
Info on docstrings in other languages than Python can be found on Wikipedia.