Frequently Asked Questions

What is Docstring in Python?

The docstring is a document or explanation of a Python class or function. It makes it easy to understand the functionality of code without having to read the details of implementation.


The functionality of the below function sum() can easily be understood using the doc string present in “”” triple quotes.

def sum(a, b):
    Add up two integer numbers.
    This function simply adds the two number using the ``+`` operator.
    a : int
       First number to add.
    b : int
        Second number to add.
        The sum of ``a`` and ``b``.
    >>> sum(2, 3)
    return num1 + num2

Other Popular Questions