What is docstring in Python?

The docstrings are declared using """triple double quotes""" just below the class, method or function declaration. All functions should have a docstring.

The docstrings can be accessed using the __doc__ method of the object or using the help function.

Example

def my_function(): 
    """This is my function documentation."""
    
print("Output Using __doc__:")
print(my_function.__doc__)
  
print("Using help:")
help(my_function) 

Output

Using __doc__:
This is my function documentation.
Using help:
Help on function my_function in module __main__:

my_function()
    This is my function documentation.