Skip to content

Getting Help in a Jupyter Notebook

Getting Help in a Jupyter Notebook

There are a couple of different ways to get help when using a Jupyter notebook.

Get help using dir

Typing dir() and passing in a function, method, variable or object shows the possible object, method and function calls available to that object. For example, we can investigate the different functions in the glob module, part of Python's Standard Library, by importing glob, then calling dir(glob).

In [1]:
import glob
dir(glob)

Out[1]:
['__all__',
 '__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__spec__',
 '_glob0',
 '_glob1',
 '_glob2',
 '_iglob',
 '_ishidden',
 '_isrecursive',
 '_iterdir',
 '_rlistdir',
 'escape',
 'fnmatch',
 'glob',
 'glob0',
 'glob1',
 'has_magic',
 'iglob',
 'magic_check',
 'magic_check_bytes',
 'os',
 're']

Get help using Tab

After typing the name of a variable, object or function following the . character hit the [Tab] key. Typing [Tab] brings up a list of available options. Scroll through the list or type a letter to filter the list to certain starting letters. Use [Enter] to select the option you want.

Tab completion can also be used during module import. Hit [Tab] after typing the module name to see which functions and classes are available in that module.

from math import <tab>

Get help using the help() function

After importing a module, you can use the help() function to see documentation about the command if it is available.

In [2]:
import math
help(math.sin)

Help on built-in function sin in module math:

sin(...)
    sin(x)

    Return the sine of x (measured in radians).

After importing a module, you can view help on the imported module by typing the module name followed by a question mark ?
In [3]:
import statistics
statistics.mean?

Signature: statistics.mean(data)
Docstring:
Return the sample arithmetic mean of data.

>>> mean([1, 2, 3, 4, 4])
2.8

>>> from fractions import Fraction as F
>>> mean([F(3, 7), F(1, 21), F(5, 3), F(1, 3)])
Fraction(13, 21)

>>> from decimal import Decimal as D
>>> mean([D("0.5"), D("0.75"), D("0.625"), D("0.375")])
Decimal('0.5625')

If ``data`` is empty, StatisticsError will be raised.
File:      ~/anaconda3/envs/book/lib/python3.6/statistics.py
Type:      function

You can view the source code where a particular function is defined using a double question mark ??

In [4]:
import statistics
statistics.mean??

Signature: statistics.mean(data)
Source:   
def mean(data):
    """Return the sample arithmetic mean of data.

    >>> mean([1, 2, 3, 4, 4])
    2.8

    >>> from fractions import Fraction as F
    >>> mean([F(3, 7), F(1, 21), F(5, 3), F(1, 3)])
    Fraction(13, 21)

    >>> from decimal import Decimal as D
    >>> mean([D("0.5"), D("0.75"), D("0.625"), D("0.375")])
    Decimal('0.5625')

    If ``data`` is empty, StatisticsError will be raised.
    """
    if iter(data) is data:
        data = list(data)

Help online

Help is also available online at in the offical Jupyter documentation:

http://jupyter.readthedocs.io/en/latest/

You can always try to find help by typing something into Google. The site Stack Overflow is devoted to programming questions and answers. The highest rated answers on Stack Overflow are at the top of each question page.