Docstring

noun

say it: “DOK-string” /ˈdɑkˌstrɪŋ/

A string in triple quotes right under a function's or class's first line that explains what it does; editors show it when you hover over the name.

What is a docstring?

A docstring is a string in triple quotes right under a function (or class) line that explains what it does. Editors show it when you hover over the name.

def shipping_cost(weight_kg):
    """Return the shipping cost in dollars for a parcel."""
    return 5 + weight_kg * 2

In a sentence

  • “The docstring says the function returns the shipping cost in dollars.”
  • “Hovering over shipping_cost in VS Code showed its docstring.”

Level: Apprentice · More Python terms at this level

Updated