0 votes
in Python by
What is docstring in Python?

3 Answers

0 votes
by

A Python documentation string is known as docstring, it is a way of documenting Python functions, modules and classes.

0 votes
by

Python docstrings are the string literals enclosed in triple quotes that appear right after the definition of a function, method, class, or module. These are generally used to describe the functionality of a particular function, method, class, or module. We can access these docstrings using the __doc__ attribute. Here is an example:

def square(n):

    '''Takes in a number n, returns the square of n'''

    return n**2

print(square.__doc__)

 Ouput: Takes in a number n, returns the square of n 

0 votes
by
Python lets users include a description (or quick notes) for their methods using documentation strings or docstrings. Docstrings are different from regular comments in Python as, rather than being completely ignored by the Python Interpreter like in the case of comments, these are defined within triple quotes.

Syntax:

"""

Using docstring as a comment.

This code add two numbers

"""

x=7

y=9

z=x+y

print(z)
...