Python Documentation Strings

To document what an object does, you can place a triple-quoted string directly after the object.

Example

Using the Python Shell, enter this function:

Python
def sayHello(name):
    """A simple function that says hello"""
    print(f'Hello {name}.')

You can access this comment using:

Python
help(sayHello)

Output

Help on function sayHello in module __main__:

sayHello(name)
    A simple function that says hello

Notes

Note the colon (:) after the function name.

This is a great way to provide another programmer with a description of what your functions do!

You can provide multi-line help.  For example:

Python
def sayHello(name):
    """
    A simple function 
    that says hello
    """

  print(f'Hello {name}.')

Again, consider describing more why the object exists and less what the object does.

Alternative

You can also specify the documentation for a function separate from a document string embedded in the function by assigning the __doc__ variable for that function.  For example:

Python
sayHello.__doc__ = 'Say hello to someone.'

An advantage to using this style of object documentation is that it doesn't clutter your object's code with the documentation -- all the documentation can be placed in a separate code file or at the end of a code file.