Concepts / Getting Started with the Python Interpreter

Getting Started with the Python Interpreter

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

  • Programming

A Documentation Shortcut

When you are working in the Python interpreter, you may encounter a function, statement, or other object that you do not yet understand. Python provides a built-in help system so you can request documentation without leaving the interpreter. The help() function is especially useful for quick lookups while you are actively coding.

The central choice is whether you call help() with an argument for a focused lookup or without an argument to enter interactive help mode.

shows documentationentersexit withreturns tohelp('function_name')Focused documentationPython promptReturns automaticallyhelp()Interactive helpHelp interfaceBrowse or search topicsqExit command
How does Python behave when help() receives an argument compared with when it receives no argument?

Focused Lookups at the Prompt

To request documentation about one particular function, call help() with an argument. The source material presents the common form help('function_name'), where the function name is supplied as a string. Python displays documentation about the requested function and then returns you to the normal interpreter prompt automatically. This mode is useful when you want a quick answer about what a function does or how to use it.

python

Looking Up One Function

You are at the Python prompt and need quick documentation about a function.

Request: Call help() with the function name as a string, using the form help('function_name').

Read: Python displays documentation for the requested function.

Continue: After the documentation is displayed, Python returns you to the normal prompt automatically.

A focused help request gives you documentation and returns control to the interpreter without requiring you to leave it.

Entering Interactive Help

Calling help() without an argument starts interactive help mode. In this mode, you can browse and search for topics instead of requesting only one known item. Unlike a focused lookup, interactive help does not return to the Python prompt automatically. You remain in the help interface until you exit it.

enter help()requestpressreturn toPython promptNormal interpreterInteractive helpBrowse or searchTopic requestAnother topicPython promptInterpreter restoredqExit help
What happens to the interpreter prompt after help(), how do you request another topic, and how do you return to normal Python input?
python
  1. At the normal Python prompt, enter help() without an argument.
  2. Use the interactive help interface to browse or search for a topic.
  3. Read the documentation that the help system displays.
  4. Press q when you want to leave interactive help.
  5. Continue working at the normal Python prompt.

Teaching the Help System About Itself

The help system is self-documenting. You can use help() to learn about help itself, including information about the help system and how to navigate it. This creates two related but different actions: calling help(help) requests focused documentation about help, while calling help() with no argument enters the interactive interface in which you can browse or search for topics.

pass as topicreturns tocall without argumentopenshelpThe help functionhelp(help)Documentation about helpPython promptAutomatic returnHelp topicsBrowse or searchhelp()Interactive help mode
How can help(help) reveal information about help(), and how is that different from entering help() with no argument?

Learning About help()

You know that Python has a built-in help system, but you want information about the help system itself.

Focused route: Use help(help) to request focused documentation about help.

Interactive route: Use help() with no argument when you want to enter the interactive help interface and browse or search for information about the help system and its navigation.

Choose by goal: Use the focused route when you want documentation about help itself; use the interactive route when you want to explore topics.

Python's help functionality can explain both other Python objects and its own capabilities.

Mistakes Beginners Make

  • Expecting help() without arguments to return immediately to the Python prompt

    Calling help() without arguments enters an interactive mode that remains active until you exit it.

    Fix: Press q to leave interactive help and return to the normal Python prompt.

  • Confusing a focused lookup with interactive help

    A focused lookup displays documentation for a specific function and returns automatically, while help() without arguments opens a browsable and searchable interface.

    Fix: Use an argument for a quick, specific lookup and no argument for interactive browsing.

  • Assuming the help system can only explain other functions

    The help system is self-documenting and can be used to learn about its own capabilities and navigation.

    Fix: Use help(help) for focused information about help, or enter help() to explore the help system interactively.

  • Leaving the interpreter to look up every small question

    The built-in help system provides immediate documentation inside the interpreter and does not require an internet connection.

    Fix: Try help() for a fast answer about a specific function, statement, or object; use broader tutorials or online documentation when you need more extensive teaching.

FormPurposeWhat happens next
help('function_name')Request documentation about one specific functionDocumentation is displayed and the interpreter prompt returns automatically
help()Enter interactive help to browse and search for topicsThe help interface remains active until you press q
help(help)Request focused information about the help system itselfIt follows the focused-lookup pattern and returns to the prompt automatically

Practice the Prompt-to-Help Cycle

EASY

Imagine that you are working at the Python prompt. Decide which help form you would use in each situation: you want quick documentation about one function; you want to browse and search for topics; you want to learn about the help system itself; or you are finished browsing and want to return to Python.

Hints
  • A focused lookup includes an argument.
  • Interactive browsing starts with no argument.
  • The help system can be supplied as its own topic.
  • The interactive interface is exited with q.

What do you think happens?

You enter help() with no argument and finish reading one topic. What must you do before normal Python input is available again?

  • Call help() a second time
  • Press q
  • Leave the interpreter
  • Pass the topic as a string
Reveal answer

Answer: Press q

The no-argument form enters interactive help mode, and q exits that interface and returns you to the normal Python prompt.

Working Habits to Keep

Use the argument form for a quick lookup when you already know what you want to investigate. Use the no-argument form when you need to browse or search. If you enter interactive help, remember that q is the route back to the Python prompt. Treat help() as an immediate in-interpreter reference, while recognizing that broader tutorials or online documentation may be more appropriate for detailed explanations, examples, or wider concepts.

  1. The built-in help() function keeps documentation close to your Python work. Passing an argument requests focused documentation and returns you to the prompt automatically. Calling help() without an argument opens an interactive interface for browsing and searching, and q exits that interface. Because the help system is self-documenting, help(help) can provide focused information about help itself.

Key Takeaways

  • Use help('function_name') for focused documentation about a specific function.
  • Use help() without arguments to enter interactive help mode for browsing and searching.
  • Press q to exit interactive help and return to the normal Python prompt.
  • Use help(help) to request focused information about the help system itself.
  • Use help() for immediate lookups during interpreter work, while using broader tutorials when you need more extensive explanations.