my-server
← Wiki

Docstring

A docstring is a string literal that annotates an associated section of source code. It provides for the same utility as a comment, but unlike a comment is a string literal and is retained as part of the running program. Some development tools display docstring information as part of an interactive help system.

Programming languages that support docstring include Python, Lisp, Elixir, Clojure, Gherkin, Julia and Haskell. Tools that leverage docstring text include cobra-doc (Cobra), doctest (Python), Pydoc (Python), Sphinx (Python).

Examples

Elixir

Documentation is supported at language level, in the form of docstrings. Markdown is Elixir's de facto markup language of choice for use in docstrings:

Lisp

In Lisp, a docstring is known as a documentation string. The Common Lisp standard states that a particular implementation may choose to discard docstrings. When they are kept, docstrings may be viewed and changed using the DOCUMENTATION function. For instance:

Python

In Python, a docstring is a string literal that follows a module, class or function definition. It must be nothing but a string literal, not any other kind of expression. The docstring is accessible via the associated code element's <code>__doc__</code> attribute and the <code>help</code> function.

The following Python code declares docstrings for each program element:

If saved as , the following is an interactive session showing how the docstrings may be accessed:

See also

  • docblock Source code comment formatted for automated documentation generation

References

External links