Docstring in Python
* Docstring is short for documentation string.
* Triple quotes are used while writing docstrings.
* It is a string that occurs as the first statement in a module, function, class, or method definition.
* We must write what a function/class does in the docstring.
#function definition def sum(): """ calculate and print sum of two numbers """ a=int(input("Entr 1st no ")) b=int(input("Enter 2nd no ")) c=a+b print("Sum = ",c) #function calling sum()
To print doc string
Docstring is available to us as the attribute __doc__ of the function. Inorder to print doct string we have issue the command as
Note:two underscores before and after doc
calculate and print sum of two numbers
>>> print(sum.__doc__) calculate and print sum of two numbers >>>