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.
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.
Python's built-in help() function provides immediate access to documentation about functions, statements, and objects without leaving the interpreter.
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.
| Call | Mode | How you leave it |
|---|---|---|
| help('function_name') | Quick documentation lookup | Returns to the prompt automatically |
| help() | Interactive browsing and searching | Press q |
The argument determines whether help() performs a quick lookup or enters interactive mode.
Looking Up a Named Function
A quick documentation lookup
You need documentation about a particular Python function while remaining in the interpreter.
- 1Name the function
Write the function name as a string argument to
help(). - 2Read the documentation
Python displays documentation about that function.
- 3Continue coding
After displaying the documentation, this form returns you to the Python prompt automatically.
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.
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.
Using the tool to understand the tool
You want information about Python's own help function.
- 1Request help about help
Pass help as the object whose documentation you want to inspect.
- 2Read the displayed information
Python displays documentation about the help function.
- 3Compare the modes
Remember that
help(help)is a lookup about a named object, whilehelp()with no argument enters interactive help mode.
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 likeCalling help() and expecting Python to return to the ordinary prompt automatically
Why it failsThe no-argument form enters interactive help mode and remains there while you browse or search.
Do this insteadPress q to exit interactive help and return to the Python interpreter.
Common mistake Confusing a named lookup with interactive mode
What it looks likeTreating help('function_name') and help() as interchangeable callsWhy it failsA named argument requests documentation about a specific object, while no argument starts interactive browsing and searching.
Do this insteadUse help('function_name') for a focused lookup and help() for interactive exploration.
Common mistake Thinking help requires leaving the interpreter
What it looks likeLeaving the coding environment immediately whenever a function or statement is unfamiliar
Why it failsPython provides built-in documentation about functions, statements, and other objects directly at the prompt.
Do this insteadTry the appropriate help() form first when you need a quick answer.
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
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.
- 1The 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 callhelp(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.