Docstring

Domain: Programming Fundamentals

🎯 Motivation

A docstring is a special comment right after a function/class definition that documents what it does. Tools can extract them.

πŸ“‹ Concrete Example

def add(a, b): '''Return the sum of a and b.''' return a + b - the triple-quoted string is a docstring. help(add) shows it.

πŸ”— Analogy

A label on a filing cabinet drawer - β€˜Tax documents 2023’ tells you what’s inside without opening it. Docstrings tell you what a function does without reading its code.