Docstrings in Python

Docstrings are used to document your functions, classes, modules, and methods.

A documentation is formal definition of what your function does, what it expects as arguments, and what it returns, including the types of the arguments and return.

We use triple quotes to document our function right after the function header.

def multiply(x, y):
    '''
    Returns the multiplication of two numbers.

    Parameters:
    x (int): an integer number
    y (int): another integer number

    Returns:
    int: multiplication of x and y
    '''
    return x * y

You can easily see the docstring of a feature in Python through the doc attribute.

print(multiply.__doc__)
    Returns the multiplication of two numbers.

    Parameters:
    x (int): an integer number
    y (int): another integer number

    Returns:
    int: multiplication of x and y