Python help()
Function
The help() function in Python is a built-in tool that gives you quick access to documentation about Python objects — such as functions, classes, modules, and keywords.
This is a very useful function for beginners who want to understand what a function or module does without searching online.
Syntax
help(object)
or, simply:
help()
Parameters:
object
– Optional. Can be a function, class, module, keyword, or anything Python can describe.
Returns:
- Displays the help documentation in the console. Does not return a value.
Example 1: Help on a Function
help(len)
Output (shortened):
Help on built-in function len in module builtins:
len(obj, /)
Return the number of items in a container.
Example 2: Help on a Module
import math
help(math)
Output (first few lines):
Help on module math:
NAME
math - This module provides access to the mathematical functions...
FUNCTIONS
acos(...)
acosh(...)
...
Example 3: Help Without Arguments
help()
This opens an interactive help utility in the terminal. You can type topics like modules
, keywords
, symbols
, or topics
.
To exit, press q
or use quit
.
Use Case: Why Use help()
?
- To explore what a built-in function does
- To view available functions inside a module
- To quickly understand how to use a class or method
Common Mistakes
- Do not pass a string:
help("len")
will work but gives help on the string, not the function. - Use object reference: Always pass the actual function or module (like
len
, not"len"
).
Interview Tip
If you’re in an environment without internet (like a coding test), help()
can give you quick guidance on syntax and usage.
Summary
help()
displays documentation for Python objects.- Great for understanding built-in functions and modules.
- Also works interactively with no arguments.
Practice Task
Try using help()
on the following Python objects:
str
list
abs
dict
Example:
help(str)