Help() function in Python

Overview
The Python help() function invokes the built-in interactive help system that displays the documentation of modules, functions, classes, keywords, etc.
Syntax of help() in Python
The syntax for help() is
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
Parameters of help() in Python
The help() function in python programming takes one parameter.
object (optional)- to call the help of the given object If no argument is passed, the interactive help utility starts up on the console.
Return Values of help() in Python
The help() function in python returns a help page with detailed documentation of a particular object passed as a parameter(if any).
Example of help() in Python
Let us see the implementation of help() on the print function in python.
Code:
Output:
The above program displays the documentation of python's built-in print function.
What is help() in Python, and how does it work?
Python has an in-built system using which we can get help regarding any module, classes, functions, and keywords. This help utility can be accessed using Python's help() function in the REPL. When we call this function and pass an object to it, it returns the help page or the documentation for the object.
Python help() docstring
The docstrings (documentation strings) are the '''triple single quotes''' or """triple double quotes""" that are declared just below the class, method, or function declaration. These docstrings can be accessed using the __doc__ method or the help function.
Code:
Output:
In the above program, we created a test function having docstrings declared, and we accessed it using the __doc__ first and then using the help function.
Scaler Placement Report and Statistics
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Examples of help() in Python
Example 1: Help on User-Defined Classes
The Help function output can also be defined for user-defined functions and classes. These are nested inside triple quotes and are the first statement within a class, function, or module.
Code:
Output:
Example 2: Help on the class list in module built-in
If the object is a list, it opens the list module and its class.
Code:
Output:
Turn Learning into Career Growth
Example 3: What If no help or info is present?
If we encounter a situation where no help or info is present for that particular passed object, it shows a message in the console and returns None.
Code:
Output:
Example 4: What if a string is given as an argument
If the string is passed as an argument, then the string is treated as the name of a module, function, class, keyword, or documentation topic, and a help page is printed on the console.
For example -
Output:
In the above program, although we passed 'def' as a string argument, we still got the documentation for Python's defining function.
Example 5: What if no argument is passed
The help() function can be used without an argument. If you run the function without an argument, the interactive Python's help utility will be started on the interpreter console. You have to type the following command on the Python console.
Code:
This will return the Python's help utility, on which you can type the name of the object you need to get help about.
Input:
Output:
To quit the help utility and return to the interpreter, you need to type quit and press enter.
Output:
Conclusion
- Python has an in-built system using which we can get help regarding any module, classes, functions, and keywords.
- When we call the help() function and pass an object to it, a help page containing the documentation for the object is returned.
- If we run help without any argument, a help utility is opened where we can get help about objects in an interactive way.
- When no help is present for the passed argument object, it shows a message in the console and returns None.




