Docstrings are triple quoted strings which can span multiple lines.
They are often used to document functions. In that case, the docstring
must start at the first line of the function. The docstring can be
accessed using the function's __doc__ property.
Example:
>>> def average(*n):
"""Returns the average value of the values passed in"""
count = 0
sum = 0
for i in n:
count = count + 1
sum = sum + i
return sum / count
- print(average.__doc__) # displays average's docstring
- average(14, 3, 2, 9, 7) returns 7.0
- average(1, 1, 1, 1, 7) returns 2.2