Python Docstrings

python_tutorials

As already pointed out in a previous article titled Commenting Python Code you have learned that documentation is an essential, and a continuous step in the process of software development. The article mentioned above briefly introduced the concept of docstrings which is a way to create documentation for your Python code from within the code. This in-code documentation works for modules, classes, methods, and functions, and it is the preferred way to document all Python code.

There is a lot more to it, and that’s why we will have a closer look at this subject in this article. We’ll cover conventions on how to write docstrings correctly, as well as various docstring formats that are used in practice, followed by accessing a docstring from your Python script. And lastly, we’ll present you a number of tools in order to use and evaluate docstrings.

Diving into Docstrings

The term docstring is an abbreviation for documentation string, and describes your source code – i.e. what your function, module, or class does. It is added as a regular comment right below the head of a function, module, class, or method.

A typical example looks as follows, and is taken

To finish reading, please visit source site