Complete guide to Python's help function covering basic usage, modules, classes, functions, and custom help documentation.
Last modified April 11, 2025
This comprehensive guide explores Python’s help function, which provides interactive documentation for Python objects. We’ll cover basic usage, modules, classes, functions, and custom help documentation.
The help function is Python’s built-in interactive help system. When called with no arguments, it starts the interactive help utility.
With arguments, it displays documentation about the specified object. It works with modules, functions, classes, methods, keywords, and other Python objects.
Here’s how to use help in interactive mode to explore Python’s documentation system.
interactive_help.py
help()
This shows how to enter Python’s interactive help system. Once inside, you can explore documentation for various objects, keywords, and modules.
Type quit to exit the interactive help system and return to the Python interpreter.
You can get documentation for any built-in function by passing it to help. This example shows how to get help for print.
builtin_help.py
help(print)
This displays the full documentation for the print function, including its parameters and default values. The same approach works for all built-in functions.
The output shows the function signature, parameter descriptions, and usage examples when available.
help can display documentation for entire modules. This example shows how to get help for the math module.
module_help.py
import math
help(math)
This displays comprehensive documentation for the math module, including all available functions, constants, and their descriptions.
You can scroll through the output to explore all available mathematical operations in the module.
help provides detailed information about classes, including methods, attributes, and inheritance. This example examines the list class.
class_help.py
help(list)
This displays the complete class documentation, including constructor signatures, all available methods, and their descriptions.
The output helps understand how to use the class and what operations it supports.
You can provide help documentation for your own functions and classes using docstrings. This example demonstrates custom help.
custom_help.py
def calculate_area(radius): “““Calculate the area of a circle.
Args:
radius (float): The radius of the circle in meters
Returns:
float: The area in square meters
"""
return 3.14159 * radius ** 2
help(calculate_area)
This shows how docstrings become part of the help system. The function’s docstring appears when help is called on it.
Well-written docstrings make your code self-documenting and more usable through the help system.
Use docstrings: Always document your functions and classes with docstrings
Be descriptive: Include parameter types, return values, and examples
Explore interactively: Use help() in the REPL to discover functionality
Check modules: Use help on imported modules to learn their API
Follow conventions: Use standard docstring formats like Google or NumPy style
My name is Jan Bodnar, and I am a passionate programmer with extensive programming experience. I have been writing programming articles since 2007. To date, I have authored over 1,400 articles and 8 e-books. I possess more than ten years of experience in teaching programming.
List all Python tutorials.