Open In App

Help function in Python

Last Updated : 29 Nov, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In Python, the help() function is a built-in function that provides information about modules, classes, functions, and modules. In this article, we will learn about help function in Python.

help() function in Python Syntax

Syntax: help([object])

Parameters (Optional) : Any object for which we want some help or the information.

If the help function is passed without an argument, then the interactive help utility starts up on the console.

What is Help function in Python?

The Python help function is used to display the documentation of modules, functions, classes, keywords, etc. It provides information about modules, classes, functions, and methods. It is a useful tool for getting documentation and assistance on various aspects of Python. 

Python help() function Examples

Simple help() Program

In this example, we are using help() without any object to access documentation in Python.

Python3




help()


Output

Welcome to Python 3.7's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at https://docs.python.org/3.7/tutorial/.

Enter the name ...


Help with Print Function in Python

Let us check the documentation of the print function in the Python console.

Python3




help(print)


Output

Help on built-in function print in module builtins:
print(...)
    print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
    Prints the values to a stream, or to sys.stdout by default.
    Optional keyword arguments:
    file:  a file-like object (stream); defaults to the current sys.stdout.
    sep:   string inserted between values, default a space.
    end:   string appended after the last value, default a newline.
    flush: whether to forcibly flush the stream.

Help on User Defined Class in Python

Help function output can also be defined for user-defined functions and classes. The docstring(documentation string) is used for documentation. It is nested inside triple quotes and is the first statement within a class or function or a module. Let us define a class with functions.

Python3




class Helper:
    def __init__(self):
        '''The helper class is initialized'''
 
    def print_help(self):
        '''Returns the help description'''
        print('helper description')
 
 
help(Helper)
help(Helper.print_help)


Output 

Help on class Helper in module __main__:
class Helper(builtins.object)
 |  Methods defined here:
 |  
 |  __init__(self)
 |      The helper class is initialized
 |  
 |  print_help(self)
 |      Returns the help description
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)
Help on function print_help in module __main__:
print_help(self)
    Returns the help description

If no Help or Info is Present

In this example, we are using help() if no help or info is present and access documentation in Python.

Python3




print(help("GeeksforGeeks"))


Output

No Python documentation found for 'GeeksforGeeks'.
Use help() to get the interactive help utility.
Use help(str) for help on the str class.

None



If a string is given as an argument

In this example, we are passing a string inside the help function to access documentation in Python.

Python3




help('gfg')


Output

No Python documentation found for 'gfg'.
Use help() to get the interactive help utility.
Use help(str) for help on the str class.




Python help() function docstring

The docstrings are declared using ”’triple single quotes”’ or “””triple double quotes””” just below the class, method or function declaration. All functions should have a docstring.

Accessing Docstrings: The docstrings can be accessed using the __doc__ method of the object or using the help function.

Python3




def my_function():
    '''Demonstrates triple double quotes
    docstrings and does nothing really.'''
 
    return None
 
print("Using __doc__:")
print(my_function.__doc__)
 
print("Using help:")
help(my_function)


Output

Using __doc__:
Demonstrates triple double quotes
    docstrings and does nothing really.
Using help:
Help on function my_function in module __main__:

my_function()
    Demonstrates triple double quot...




Previous Article
Next Article

Similar Reads

How to make a box with the help of nested loops using Python arcade?
Arcade library is modern framework currently used in making 2D games. Nested loop discussed here are analogous to nested loops in any other programming language. The following tutorial will step by step explain how to draw a box with the help of nested loops using Python's arcade module. Import arcade library.Here we will be using circles to form a
2 min read
Python: Difference between dir() and help()
In Python two commonly used functions for exploring objects, modules, and their attributes are dir() and help(). While both are useful for gaining insights into Python code, they serve distinct purposes. This article aims to clarify the differences between dir() and help() and guide developers on when and how to use each effectively. What is dir()
5 min read
PyQt5 – What's this help text for Label | setWhatsThis() method
In PyQt5, there are lots of widgets and while making an application we end up putting lots of widget. Sometimes, we can remember why this widget is used but not always, neither it seems a good practice. That's why for back-end purposes, PyQt5 allows us to set help text. In this article, we will see how to set and access help text for label. To set
2 min read
PyQt5 – Setting and accessing WHATS THIS help text for Status Bar
n PyQt5 there are lots of widgets and bars and when we tend to make an application, we end up putting lots of windows and for each window there exit status bar. Sometimes we can't remember why this status bar is used and what is this status bar. That’s why for back-end purposes PyQt5 allows us to set help text. In this article we will see how to se
2 min read
PyQt5 – How to create and get the help text of Push Button ?
PyQt5 offers us to set the help the text for the push button, help text is the raw information about the push button i.e this button perform what function, how it is linked with the source etc. In this article we will see how to create and get the help text of Push Button. In order to do this we will use setWhatsThis method to create help text and
2 min read
PyQt5 - setWhatsThis() help text of Radio button
In this article we will see how we can set and access the help text of the radio button. Help text is the text which is used to know about the future information or what new information we can get about the radio button, in order to set help text we use setWhatsThis method and for accessing we use whatsThis method. For setting help text to radio bu
2 min read
PyQt5 - Setting help text of the combo box
In this article we will see how we set help text to the combo box, help text is basically used to tell the programmer about the emergency information like reference links etc, programmer set help text to the combo box so that when some other programmer get difficulty in understanding the combo box, he/she can take help from the help text. In order
2 min read
PyQt5 - Accessing help text of the combo box
In this article we will see how we can access help text to the combo box. Help text is basically used to tell the programmer about the emergency information like reference links etc, programmer set help text to the combo box so that when some other programmer get difficulty in understanding the combo box, he/she can take help from the help text. In
2 min read
PyQt5 QCommandLinkButton - Setting Help Text
In this article we will see how we can set the help text of the QCommandLinkButton. Help text is the text used to tell the other user about the usage information about the command link button. It contains the information which can be used to check the usage, limitation etc. In order to do this we use setWhatsThis method with the command link button
1 min read
PyQt5 QCommandLinkButton - Getting Help Text
In this article we will see how we can get the help text of the QCommandLinkButton. Help text is the text used to tell the other user about the usage information about the command link button. It contains the information which can be used to check the usage, limitation etc. Help text can be added to the command link button with the help of setWhats
2 min read
Practice Tags :