CKTIS / Python
function.__doc__
A function stores its documentation string in this attribute, or None if it has no docstring.
Version: Python 3.14; repository image, production runtime not attested
Syntax
documentation = function.__doc__A function stores its documentation string in this attribute, or None if it has no docstring.
function.__doc__
A string literal as the first statement supplies the documentation. Writing through an alias changes the same object's metadata without changing the function body.
plain has None, and area(3) still returns 9 after editing its description.
def f():
n=1
"Late string."
assert f.__doc__ is None
f.__doc__='text'
assert f.__doc__=='text'
Examples
def area(n):
"""Return the area of a square."""
return n*n
def plain(): pass
alias = area
print(area.__doc__, plain.__doc__)
alias.__doc__ = "Area in cm²."
print(area.__doc__, area(3))
Result
Return the area of a square. None Area in cm². 9
plain has None, and area(3) still returns 9 after editing its description.