Skip to content

Getting Help in a Jupyter Notebook

Getting Help in a Jupyter Notebook

There are a couple different ways to get help when using a jupyter notebook

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 urllib module, part of Python's Standard Library, by importing urllib, then calling dir(urllib)

In [6]:
import urllib
dir(urllib)

Out[6]:
['__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 '__spec__',
 'error',
 'parse',
 'request',
 'response']

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 importing, to see which functions and classes are available in a given module.

from math import <tab>

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 [10]:
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).

using ? and ??

After importing a module, you can view help on it by typing the module name followed by a question mark ?

In [11]:
import statistics
statistics.mean?

You can view the source code where a particular function lives using a double question mark ??
In [12]:
statistics.median??

Help online

Help is also avaiable online at on the Jupyter Notebook docs:

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.