Python-Docstring
Wed 12 November 2025
# created : 20250113
# https://www.scientecheasy.com/2022/09/docstring-in-python.html/
# docstring in python
# Function with a Docstring.
def getSum(x, y):
"""This is a docstring
This method takes two argument values and returns the summation of it."""
print("Sum = ", (x + y))
getSum(20, 40) # Calling function.
print(getSum.__doc__) # Calling __doc__ method to print docstring.
Sum = 60
This is a docstring
This method takes two argument values and returns the summation of it.
def info(name:str,age:int):
""" this funtion will get the name and age of the user
if the age is not a integer it will raise a error
"""
if not isinstance(age,int):
raise ValueError("age must be a integer")
print("details = ",(name,age))
info("jerin",23)
details = ('jerin', 23)
print(info.__doc__) # --> this will print only the docstring
this funtion will get the name and age of the user
if the age is not a integer it will raise a error
def getSum(x, y):
"""This is a docstring
This method takes two argument values and returns the summation of it."""
print("Sum = ", (x + y))
getSum(20, 40)
print(getSum.__doc__)
Sum = 60
This is a docstring
This method takes two argument values and returns the summation of it.
def getSquare(num):
'''This method takes a number num and returns the square of its value.'''
return num * num
print(getSquare.__doc__)
sq_value = getSquare(20)
print(sq_value)
This method takes a number num and returns the square of its value.
400
Score: 10
Category: python-basics