Python help() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Built-in

Definition

In Python, help(obj) prints documentation for any object: its signature and its docstring, the string literal at the top of a function, class, or module. help(len) explains len(), and help("keywords") lists Python keywords.

Called with no argument, it starts an interactive help prompt in the shell. It is powered by the standard pydoc module, which can also render the same text into a string with pydoc.render_doc().

help() is a built-in function: it lives in the builtins module, so it is always available without an import.

Syntax

Pass an object, or a string to search for a topic.

python
help(obj)
help("topic")
help()                # interactive prompt
CallWhat it does
help(len)Docs for a built-in function.
help(str.split)Docs for a method.
help("keywords")Lists Python keywords.
help(my_function)Shows your own docstring.

The exact help text varies between Python versions, and long pages open in a pager in the terminal; press q to quit.

Library declarations
python
help()
help(request)
# provided by the site module; built on pydoc

Parameters

ParameterDescription
requestOptional. An object, or a string naming a module, keyword, or topic.

Return Value

Return ValueDescription
NoneIt prints documentation; it does not return it.

Python Examples

Example 1 — help() on a Built-in Function

Show the documentation of len().

python
help(len)

How It Works

  1. Header line. It names the object and the module it comes from, builtins.
  2. Signature. len(obj, /) shows one positional-only parameter.
  3. Docstring. The indented text is the function's documentation.
  4. Version differences. Wording and layout can change between Python releases.

Example 2 — help() Shows Your Own Docstrings

Write a function with a docstring and ask for help on it.

python
def area(width, height):
    """Return the area of a rectangle.

    Both arguments must be numbers.
    """
    return width * height


help(area)

How It Works

  1. Docstring first. The triple-quoted string right after def becomes area.__doc__.
  2. Script module. Run directly, the function lives in the module __main__.
  3. Cleaned indentation. help() removes the docstring's leading indentation before printing.
  4. Summary line. Keep the first line short; tools show it in lists.

Example 3 — Get Documentation as a String with pydoc

Render class documentation into a string, check it, and read a docstring directly.

python
import pydoc


class Greeter:
    """Say hello in different styles."""

    def hello(self, name):
        """Return a friendly greeting."""
        return "Hello, " + name


text = pydoc.render_doc(Greeter, renderer=pydoc.plaintext)
lines = text.splitlines()
print(lines[0])
print("Return a friendly greeting." in text)
print(Greeter.hello.__doc__)

How It Works

  1. No printing, no pager. pydoc.render_doc() returns the help text as a string.
  2. Plain text. renderer=pydoc.plaintext avoids the bold formatting used in terminals.
  3. Search the text. The method's docstring is part of the rendered page.
  4. Direct access. __doc__ gives the raw docstring when that is all you need.

Frequently Asked Questions

Call help(obj) with any function, class, module, or method, or help("topic") for keywords and topics.
Press q to leave the pager. In the interactive help> prompt, type quit or press Enter on an empty line.
From docstrings and signatures, formatted by the pydoc module.
Put a docstring as the first statement of your function, class, or module.
The wording varies by Python version and terminal. The content comes from the same docstrings.

Next: hex()

Hexadecimal string of an integer, prefixed with 0x.

hex() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful