Help and documentation

Author

Marie-Hélène Burle

This section shows you how to access help and documentation from within Python.

Module

You can get help on a module (we will discuss modules later in the course) thanks to the help function, but only after you have loaded that module into your session:

import os
help(os)
Help on module os:

NAME
    os - OS routines for NT or Posix depending on what system we're on.

MODULE REFERENCE
    https://docs.python.org/3.13/library/os.html

    The following documentation is automatically generated from the Python
    source files.  It may be incomplete, incorrect or include features that
    are considered implementation detail and may vary between Python
    implementations.  When in doubt, consult the module reference at the
    location listed above.

...

Functions

You can also access the internal Python documentation on a function with help:

help(max)
Help on built-in function max in module builtins:

max(...)
    max(iterable, *[, default=obj, key=func]) -> value
    max(arg1, arg2, *args, *[, key=func]) -> value

    With a single iterable argument, return its biggest item. The
    default keyword-only argument specifies an object to return if
    the provided iterable is empty.
    With two or more positional arguments, return the largest argument.

In Jupyter, you can also use ?max or max?.

Alternatively, you can print the __doc__ method of the function:

print(max.__doc__)
max(iterable, *[, default=obj, key=func]) -> value
max(arg1, arg2, *args, *[, key=func]) -> value

With a single iterable argument, return its biggest item. The
default keyword-only argument specifies an object to return if
the provided iterable is empty.
With two or more positional arguments, return the largest argument.

Methods of object types

Some methods belong to specific objects types (e.g. lists have a method called append).

In those cases, help(<method>) won’t work.

Example:

help(append)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[3], line 1
----> 1 help(append)

NameError: name 'append' is not defined

What you need to run instead is help(<object>.<method>).

Example:

help(list.append)
Help on method_descriptor:

append(self, object, /) unbound builtins.list method
    Append object to the end of the list.

Help while using IPython or Jupyter

When using IPython (which means also when using Jupyter Lab or Jupyter notebooks since they run IPython), you can access help by using ?.

Example:

?sum
Signature: sum(iterable, /, start=0)
Docstring:
Return the sum of a 'start' value (default: 0) plus an iterable of numbers

When the iterable is empty, return the start value.
This function is intended specifically for use with numeric values and may
reject non-numeric types.
Type:      builtin_function_or_method

Note that, for modules, the help you get this way only contains the description. If you want to get the full documentation (including classes, functions, and data), you need to use the help function instead.