Concepts / Reading and Understanding Error Messages

Reading and Understanding Error Messages

Use help() when you need a focused lookup. It keeps you in the interpreter and does not require an internet connection.

  • Programming

A Documentation Tool at the Prompt

When you are learning Python or working in the interpreter, you will encounter functions, statements, and objects you do not yet understand. Python provides a built-in help system so you can retrieve documentation without leaving the interpreter. This makes help() useful when you need a quick explanation while you are actively coding.

Definition

Python's built-in help() function provides immediate access to documentation about functions, statements, and objects without leaving the interpreter.

Key point

Use help() when you need a focused lookup. It keeps you in the interpreter and does not require an internet connection.

Two Ways to Ask for Help

The help system has two important modes. In the first mode, you pass an object name, commonly a function name written as a string. Python displays documentation about that object and then returns to the prompt automatically. In the second mode, you call help() with no argument. Python enters an interactive help interface in which you can browse and search for topics. This mode remains active until you press q.

help()Object argumentfunction name as a stringDocumentationreturns to promptNo argumentInteractive helpbrowse and searchqreturn to promptcallargument suppliedno argumententerpress
What happens when Python receives an object inside help(), compared with calling help() with no argument?
CallModeHow you leave it
help('function_name')Quick documentation lookupReturns to the prompt automatically
help()Interactive browsing and searchingPress q

The argument determines whether help() performs a quick lookup or enters interactive mode.

Looking Up a Named Function

python
Worked example

A quick documentation lookup

You need documentation about a particular Python function while remaining in the interpreter.

  1. 1
    Name the function

    Write the function name as a string argument to help().

  2. 2
    Read the documentation

    Python displays documentation about that function.

  3. 3
    Continue coding

    After displaying the documentation, this form returns you to the Python prompt automatically.

Result

Use help('function_name') when you want a quick answer about a specific function.

Entering and Leaving Interactive Help

Calling help() with no argument changes the interaction from the ordinary Python prompt to an interactive help interface. In that interface, you can browse and search documentation for topics. Unlike a named lookup, this mode does not return to the prompt automatically. Press q to exit interactive help and return to the Python interpreter.

Python promptInteractive helphelp()Documentation topicbrowse or searchPython promptqcall help()browse or searchpress q
How does control move from the Python prompt into interactive help, through documentation pages, and back out again?
python

Learning About help Itself

The help system is self-documenting. You can use help() to enter interactive mode and search for information about the help system, its commands, and how to navigate it. This means that the tool can provide guidance about its own use instead of requiring you to remember every command before you begin.

python
Worked example

Using the tool to understand the tool

You want information about Python's own help function.

  1. 1
    Request help about help

    Pass help as the object whose documentation you want to inspect.

  2. 2
    Read the displayed information

    Python displays documentation about the help function.

  3. 3
    Compare the modes

    Remember that help(help) is a lookup about a named object, while help() with no argument enters interactive help mode.

Result

help(help) demonstrates that Python's help system can document the help function itself.

Mistakes Beginners Make

  • Common mistake

    Assuming help() with no argument behaves like a quick lookup

    What it looks like

    Calling help() and expecting Python to return to the ordinary prompt automatically

    Why it fails

    The no-argument form enters interactive help mode and remains there while you browse or search.

    Do this instead

    Press q to exit interactive help and return to the Python interpreter.

  • Common mistake

    Confusing a named lookup with interactive mode

    What it looks like
    Treating help('function_name') and help() as interchangeable calls
    Why it fails

    A named argument requests documentation about a specific object, while no argument starts interactive browsing and searching.

    Do this instead

    Use help('function_name') for a focused lookup and help() for interactive exploration.

  • Common mistake

    Thinking help requires leaving the interpreter

    What it looks like

    Leaving the coding environment immediately whenever a function or statement is unfamiliar

    Why it fails

    Python provides built-in documentation about functions, statements, and other objects directly at the prompt.

    Do this instead

    Try the appropriate help() form first when you need a quick answer.

Best practice

Use help() for quick, specific questions while you are working interactively. For detailed tutorials, examples, or broader conceptual explanations, online documentation or tutorials may be more appropriate.

Practice the Decision

EASY

Choose the appropriate help() form for each situation: you want a quick lookup about one function; you want to browse and search documentation; you want information about the help function itself.

Hints
  • A named object produces a focused documentation lookup.
  • No argument enters interactive help mode.
  • The help function can itself be supplied as the object.
  1. 1
    The key decision is whether you need one object's documentation or an interactive search. A named call such as help('function_name') displays documentation and returns to the prompt. A no-argument call, help(), enters interactive help mode, where q returns you to the interpreter. The self-referential call help(help) lets the help system document itself.

Key Takeaways

  • Python's built-in help() function provides documentation about functions, statements, and other objects inside the interpreter.
  • Use help('function_name') for a focused lookup that returns to the prompt automatically.
  • Use help() with no argument to browse and search interactively.
  • Press q to leave interactive help and return to the Python prompt.
  • Use help(help) to learn about Python's help function and its capabilities.

Related concepts

More concepts starting with R