Help() function in Python

Learn via video course
FREE
View all courses
Python Course for Beginners With Certification: Mastering the Essentials
Python Course for Beginners With Certification: Mastering the Essentials
by Rahul Janghu
1000
4.90
Start Learning
Python Course for Beginners With Certification: Mastering the Essentials
Python Course for Beginners With Certification: Mastering the Essentials
by Rahul Janghu
1000
4.90
Start Learning
Topics Covered

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

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

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.

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science

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

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

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

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

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.

See Also: