Back
+10 XP
Concept

Docstrings: Documenting What Functions Do

Triple-quote strings `"""..."""` placed directly under `def` become the function's official docstring, visible via `help(func)` and IDE tooltips.

python
def launch(thrust):
    """Fires rocket boosters with specified thrust force in kN."""
    return f"Ignition at {thrust} kN"

print(launch.__doc__)

# 98. Docstrings: Documenting What Functions Do Triple-quote strings `"""..."""` placed directly under `def` become the function's official docstring, visible via `help(func)` and IDE tooltips: ```python def launch(thrust): """Fires rocket boosters with specified thrust force in kN.""" return f"Ignition at {thrust} kN" print(launch.__doc__) ``` Docstrings are not ignored comments like `#`. Python parses them into the function object (`__doc__`) so automated documentation generators and VS Code hover popups can display them to users.

Checkpoint

Where must a docstring be placed to be recognized by Python?

Practice

Write a function `multiply(a, b)` containing the docstring `"""Returns product of a and b."""` and returning `a * b`. Print `multiply.__doc__`.

Terminal
01
Tap code blocks below to assemble
Available Blocks