VMware ESXi and vSphere Cluster Management
Using Python Help Mode and the help() Function
Learn to use Python's built-in help() function and interactive help mode to explore topics, modules, functions, classes, methods, and attributes.
Python includes a built-in documentation system that you can use directly from the interactive interpreter. The main entry point is help(), which is powered by Python's pydoc documentation mechanism.
A REPL (read-evaluate-print loop) is Python's interactive interpreter. It normally displays the >>> prompt, accepts an expression or command, evaluates it, and displays the result.
The help system is useful when you need a quick reference for unfamiliar code. It can use documentation text, object signatures, docstrings, and module metadata. A docstring is documentation text attached to a module, class, function, or method.
Start Python and enter help mode
Open a terminal or command prompt and start Python:
python
Depending on your installation, the command may be named differently, such as python3. When Python starts, you should see the normal interpreter prompt:
>>>
Call help() without an argument:
>>> help()
Python displays introductory instructions and changes the prompt to:
help>
This is the interactive help utility: a prompt-driven documentation browser separate from the normal Python prompt. At a conceptual level, its instructions tell you that you can enter a module, keyword, topic, or object name, and that commands such as topics, keywords, symbols, and modules help you discover available documentation.
Navigate the interactive help prompt
At the help> prompt, enter the name you want to investigate. You can request a module, a keyword, a language topic, or a dotted name such as a module attribute.
help> sys
help> NUMBERS
help> if
help> sys.platform
Built-in language topics commonly appear in uppercase. Use the spelling and capitalization shown by the help utility, rather than guessing a topic name.
To leave the utility, enter quit:
help> quit
>>>
The >>> prompt confirms that you are back in the normal REPL.
Browse language topics
A topic is a named help category describing a Python language concept. Topics are not the same as values in your program. For example, NUMBERS documents how numeric literals and related numeric concepts work; it does not describe one particular number stored in a variable.
>>> help()
help> topics
help> NUMBERS
The NUMBERS topic can help you understand numeric literals, which are source-code representations of numbers. Examples include integer literals such as 42, floating-point literals such as 3.14, and imaginary-number forms such as 2j.
While reading the topic, you may see references to related subjects, including:
INTEGERfor integer behavior and literalsFLOATfor floating-point valuesCOMPLEXfor complex numbersTYPESfor Python's object and type model
Use topics first when you are unsure which topic names are available:
help> topics
Look up modules and their contents
A module is a Python file or importable package namespace containing code and objects. The standard-library sys module provides information and operations related to the Python interpreter.
help> sys
A module lookup generally shows a summary, documented functions, classes, data values, and other contents. The exact sections and wording depend on the Python release.
You can request an attribute with dot notation:
help> sys.platform
An attribute is a named value associated with a module, class, or object. sys.platform is a string attribute that identifies the platform on which Python is running.
To search for installed modules, use modules:
help> modules
help> modules json
The unfiltered command can be slow because it searches many importable packages. A search term narrows the output. Some environments may also display import-related messages while scanning modules.
Inspect functions, classes, methods, and attributes
You can pass a Python object directly to help(). These examples run at the normal >>> prompt:
>>> help(len)
>>> help(str)
>>> help(list.append)
help(len) documents a built-in function. help(str) documents the built-in string type, including its behavior and methods. help(list.append) focuses on the append method belonging to lists.
For a module attribute, import the module before using a Python expression that refers to it:
>>> import sys
>>> help(sys.platform)
Without import sys, the name sys does not exist in the current interpreter session. A string lookup can sometimes avoid that requirement:
>>> help('sys')
>>> help('sys.platform')
There is an important distinction between the value of an attribute and its documentation. When sys.platform is evaluated, it produces a platform identifier such as a string. When passed to help(), Python may mainly display documentation for the object's type, str, rather than explain the platform-specific meaning of that particular value.
>>> import sys
>>> sys.platform
'...'
>>> type(sys.platform)
<class 'str'>
Use help(sys) for the module's documented attributes and consult the official library documentation when you need the exact meaning of sys.platform.
Direct help calls and help mode
Direct calls are usually quicker when you already know what you need. Help mode is better for discovery because it provides commands for finding topics, keywords, symbols, and modules.
Read and interpret help output
When help displays an object, look for these parts:
- Object kind: whether the target is a function, class, method, module, type, or another object.
- Call signature: the parameters accepted by a function, method, or class constructor.
- Description: summary text from documentation or a docstring.
- Methods and attributes: operations and named values provided by a class or module.
- Related topics: other concepts or objects that may help explain the target.
For example, a function entry may show a signature and a short description, while a class entry may include its constructor, methods, inherited members, and data attributes.
Signatures and wording can vary between Python releases. Documentation can also vary by installed package version, so do not assume that every line will look identical on another computer.
Long output may open in a pager, a tool that displays text one screen at a time. Follow the controls shown by your environment. Often a pager uses a key such as q to exit, but the on-screen instructions take precedence. After leaving the pager, you may still need to enter quit at the help> prompt.
Troubleshoot common problems
Using help without parentheses
help is a function. Entering its name alone does not start the utility and may produce a name-related result or error in some contexts.
>>> help()
>>> help(len)
Using an unimported module
This direct lookup requires an import:
>>> help(sys.platform)
NameError: name 'sys' is not defined
Import the module first, or use a string-based lookup:
>>> import sys
>>> help(sys.platform)
>>> help('sys.platform')
Seeing string documentation for sys.platform
This is expected when the target is a string-valued attribute. Evaluate sys.platform to see its current value, use type(sys.platform) to identify its type, and use help(sys) or official library documentation for the attribute's semantics.
Topic not found
The name may not be a built-in topic, or it may have the wrong spelling or capitalization. Enter topics and use a recognized name exactly as listed.
Module search is slow
modules searches installed importable packages, which can be numerous and may behave differently across environments. Use a narrow command such as modules json, or consult the package documentation directly.
Unable to return to the REPL
The help utility remains active until you explicitly leave it. Enter quit at help>. If a pager is currently visible, exit the pager using its displayed control first.
Third-party help is sparse
Undocumented third-party code may contain few docstrings or little documentation metadata. In that case, use the package's official documentation, source code, or installed documentation resources.
Scope and limitations
Built-in help is excellent for quick reference and discovery, especially while exploring unfamiliar modules or objects. It is not guaranteed to provide a complete tutorial or a detailed explanation of every value.
If a package has limited docstrings or metadata, help() may produce little useful information. For extended tutorials, examples, configuration guidance, and version-specific details, use the official Python library documentation or the package's official documentation.
For related exploration, see Python help mode, and practice combining help() with imports, dot notation, type(), and object inspection.