The built-in help() function shows the documentation of a module, class, function, method or keyword, built from docstrings and object signatures. Call help(obj) to see it in a pager, or call help() with no argument to start an interactive help session.
It is meant for the interactive interpreter, IPython and notebooks, where you want a quick answer without leaving your terminal. Under the hood it uses the pydoc module from the standard library.
Pass any object, not a string, to help(). For your own code the output comes from the docstring and the function signature:
If the function has no docstring, help() still prints the signature, which is often enough to remember argument names. For classes, help() lists the docstring, the methods, the data descriptors and the inherited members, grouped by base class.
The exact wording of built-in docstrings changes between Python releases, so treat the output above as an example, not a fixed text.
Import a module first and pass the module object:
The first call prints the module overview with every function and constant, and the second prints only sqrt. You can also pass a string to look up a name that is not imported yet, such as help("os.path"), in which case pydoc imports it for you.
Keywords and some topics are documented through strings, because they are not objects:
help("topics") lists the available documentation topics, and help("keywords") lists all reserved words. These pages come from the language reference, so they are useful for operators and syntax you rarely use.
Calling help() without arguments starts a prompt:
Type a name to read its documentation, modules to list importable modules, keywords to list keywords, and q to leave. Press q as well to quit the pager when viewing long output, and use the arrow keys or space to scroll. In the Python 3.13+ interactive shell you can also press F1 to open help for the object at the cursor, and the REPL accepts help and exit without parentheses.
help() pairs well with a few other introspection tools:
| Tool | What it gives you |
|---|---|
dir(obj) | A list of attribute and method names |
obj.__doc__ | The raw docstring as a string |
inspect.signature(obj) | The call signature as an object |
python -m pydoc name | The same text as help(), from the shell |
python -m pydoc -b | A local browsable HTML documentation server |
When you need to print documentation inside a program instead of a pager, use inspect.getdoc(obj), which also cleans up indentation. Use help() for people at a prompt, and __doc__ or inspect when your code must handle the text.
Because help() displays your docstrings, good ones make your own API self-explanatory. Put a short summary line first, then details:
The docstring convention is described in PEP 257. Whether you use Google style, NumPy style or reStructuredText, stay consistent across a project. Packages you install usually have good docstrings, so help(pandas.DataFrame.merge) or similar calls are a fast way to check a parameter.
The function probably has no docstring. Add a triple-quoted string as the first statement in the function body and help() will show it.
dir() returns the names of attributes, while help() prints the documentation for those names. Use dir() to discover, help() to read.
Yes, but it writes to the console and may open a pager, so it is rarely useful outside interactive sessions. Use inspect.getdoc() to get the text programmatically.
Press q to leave the pager. In the interactive help> prompt, type q or quit, or press Ctrl+D.
help() is the quickest way to read documentation from inside Python: pass an object for its docstring and signature, a string for keywords and topics, or nothing to open the interactive prompt. Combine it with dir() and inspect, and write clear docstrings so your own code documents itself.