- The doc string line should begin with a capital letter and end with a period.
- The first line should be a short description.
- If there are more lines in the documentation string, the second line should be blank, visually separating the summary from the rest of the description.
- The following lines should be one or more paragraphs describing the object’s calling conventions, its side effects, etc.
In Python, a docstring is a string literal used to provide documentation and information about a function, module, class, or method. It is placed as the first statement after the object’s definition and is enclosed within triple quotes (
"""). Docstrings are used to describe the purpose, usage, and behavior of the code to help developers understand and use it correctly. Docstrings serve as documentation strings and are accessible through the
__doc__ attribute of the object. They can be single-line or multi-line, and it is a recommended practice to use triple quotes for consistency and to accommodate longer descriptions.
A Python docstring is a string that is used to document a Python module, class, function, or method so that programmers understand what it does without having to study the implementation details. It is also usual practice to automatically produce online (HTML) documentation from docstrings. A Python package’s docstrings are written in the __init__.py file. It should include all of the package’s available modules and sub-packages.