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).
@moduledoc """
Documentation for my module. With **formatting**.
"""
@doc "Hello"
def world do
"World"
end
end
(defun foo () "hi there" nil)
(documentation #'foo 'function) => "hi there"
The following Python code declares docstrings for each program element:
class MyClass:
"""The class's docstring"""
def my_method(self):
"""The method's docstring"""
If saved as , the following is an interactive session showing how the docstrings may be accessed:
|
|