The help()
function displays built-in documentation for Python objects, functions, modules, and classes. It’s useful for understanding how to use functions, finding available methods, and debugging efficiently.
Example
help(print)
This prints detailed documentation about the print()
function, including its parameters and usage.
Syntax
help(object)
- object → The function, module, or class you want documentation for.
- Returns → Detailed docstring about the object.
1. Getting Help on Built-in Functions
help(len)
Shows what len()
does and how to use it.
2. Checking a Module’s Available Functions
import math
help(math)
Lists all available methods in the math
module.
3. Getting Help on a Class
class Person:
"""This class represents a person."""
def __init__(self, name):
self.name = name
help(Person)
Displays docstrings and method details.
4. Using help()
in Interactive Mode
In the Python shell, you can type:
help()
Then enter a topic like str
, list
, or print
for detailed explanations.
Key Notes
- ✔ Retrieves Python’s built-in documentation for functions, classes, and modules.
- ✔ Works with user-defined classes and functions if they have docstrings.
- ✔ Helps in debugging by showing available attributes and methods.
- ✔ Use it interactively in Python shell for quick lookups.
By using help()
, you can quickly access Python’s documentation, making it an essential tool for learning, debugging, and exploring new modules. 🚀