Skip to content

Latest commit

 

History

History
54 lines (32 loc) · 1.57 KB

docstrings.md

File metadata and controls

54 lines (32 loc) · 1.57 KB

Docstrings

Reference:

Example (Pandas):

About

Docstrings allow Python developers to document their code in a way which can be interpreted by other computers and humans alike.

"The docstring for a function or method should summarize its behavior and document its arguments, return value(s), side effects, exceptions raised, and restrictions on when it can be called (all if applicable). Optional arguments should be indicated. It should be documented whether keyword arguments are part of the interface." - PEP 257

Examples

Before documentation:

def enlarge(n):
    return n * 100

Complete, with documentation:

def enlarge(n):
    """Enlarges a number.

    Params:

        n (numeric, like int or float) the number to be enlarged

    Examples:

        enlarge(8)

        enlarge(4.5)
    """
    return n * 100

Benefits

Python tools and text editors will recognize the docstring and show a helper message to anyone who is trying to use / invoke that function:

Screen Shot 2022-07-21 at 9 50 51 PM