How to do it...

  1. Docstrings are the very first items in a module, function, class, or method; if they are put elsewhere, chances are, tools that won't recognize them as docstrings.
  2. Docstrings can be single or multi-line, as shown in the following, docstring_example.py:
        def get_pressure():            """Returns the pressure in the system."""            return sys_press        def calc_press_diff(in, out):            """Calculates the pressure drop across a valve.            :param in: Input pressure            :param out: Output pressure             :return The valve pressure drop            """            deltaP = out - in            return deltaP
  1. By convention, single-line docstrings are for obvious use cases. The reason triple quotes are used, even for one line, is to easily allow for future expansion of the docstring, if needed.
  2. A single-line ...

Get Secret Recipes of the Python Ninja now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.