Install

Vakataka, a tap away.

Add it to your home screen for a quicker way back to your next card.

iPhone or iPad
Open in Safari, tap Share, then Add to Home Screen. Choose Open as Web App if shown, then Add.
Android
Open your browser menu and choose Install app or Add to Home screen.
Computer
Use the install icon in the address bar or your browser’s app menu. In Safari on Mac, choose File → Add to Dock.

If your browser has no install option, Vakataka still works here.

A function can explain itself to its next reader

A docstring records what code is for and how to use it.

In Python, a docstring is a string placed at the start of a function, class or module. It describes the public behaviour someone needs to know, such as what a function expects and returns. A comment inside the function might explain an implementation choice; the docstring speaks to someone using the function without reading every line.

Good documentation can be short. State the contract accurately, especially any assumptions that are easy to miss. If the behaviour changes, the docstring should change with it.

A small example

A function named `square(n)` could have the docstring `Return n multiplied by itself.`

Keep in mind

A docstring can become stale. Check actual behaviour when accuracy matters.

Source & attribution

Introduction to Python Programming — Comments

OpenStax contributors · OpenStax, Rice University

CC BY 4.0. Rewritten as a self-contained explanation; the example and activity are Vakataka additions. No source images reproduced.

Source edition: 2024-07-30T19:17:56Z

Select the link to copy it.

Email · WhatsApp

A note to yourself

Create an account or sign in to keep private notes and saved cards across devices.