What is Python Docstring?
The Python docstring is used to document a Python module, function, class, or method, as it will help the programmers to understand what it does without reading the details of the implementation.
Check the example code below:
def check_leap(yearstring):
#Docstring is created using 3 double quotes like below
""" This is a sample doc string created to explain the user that this function calculates the leap year"""
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
print("It is a leap year.")
else:
print("It is Not a leap year.")
else:
print("It is a leap year.")
else:
print("It is not a leap year.")
So when you call the above function it will show the docstring when you hover over it.

No comments:
Post a Comment