Documenting your program

Python supports a special kind of comment called a docstring.

As with other comments, you use docstrings to help others understand your code. What's different about docstrings is that they work with Python's help utility so that someone can figure out what your code does without having to look at the actual file.

A docstring is always the first line in a function. It can be more than one line if you begin and end it with three quotation marks. Here's an example docstring for a function we made up called printme() :

def printme(me):

Prints its argument. h H H

Here's what you see if you ask for help on the printme() function:

Help on function printme in module main :

printme(me)

Prints its argument

For detailed instructions on writing docstrings, see Chapter 11.

Was this article helpful?

0 0

Post a comment