What is docstring in Python?

Hi, What is docstring in Python

2 Likes

Python documentation string (also known as docstring) allows you to connect documentation with Python modules, classes, functions, and methods. These docstrings are declared either within triple single quotes or within triple double-quotes. These docstrings are shown right after Python modules, classes, functions, and methods.

For example:

def cube(x):
    '''Takes in the number x, it returns the cube of x'''
    return x**2

here,

'''Takes in the number x, it returns the cube of x''' is a docstring of function cube()

Hope it helps!

1 Like