12.07
Completed
Python Docstrings Python Docstrings

Learn how to write clear, useful docstrings that explain what Python functions do, accept, and return.

Python Docstrings

Sounds useful?

Jump into the interactive version.

No setup. No account. Just Python.

Interactive Python lesson

Python Function Docstrings

A function can work perfectly and still leave its reader guessing. This Block shows you how to add clear docstrings that explain what a function does, what inputs it uses, and what it returns or displays. You will learn where a docstring belongs, how to keep simple functions to one useful sentence, and when a multi-line format makes more sense.

What you will learn:

  • Place a docstring as the first statement inside a function
  • Describe a function’s purpose, parameters, and returned or displayed result
  • Choose between concise one-line and structured multi-line docstrings
  • Keep documentation accurate when a function changes
  • Understand how docstrings differ from # comments
  • View function documentation with help() and editor hints

Write documentation that is short, accurate, and genuinely useful—so your functions are easier to understand and reuse.

> Start now 82 cards · about 8 min

Ready to practice this in the browser?

> Play now