A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/help-function-in-python/ below:

Help function in Python - GeeksforGeeks

Help function in Python

Last Updated : 11 Jul, 2025

help() function in Python is a built-in function that provides information about modules, classes, functions and modules. It is useful for retrieving information on various Python objects. Example:

Python
Output
Welcome to Python 3.13's help utility! If this is your first time using
Python, you should definitely check out the tutorial at
https://docs.python.org/3.13/tutorial/

Enter the name of any module, k...

Explanation: help() retrieves documentation using an object's __doc__ attribute. Without arguments, it starts an interactive help session, with an object, it displays method descriptions and parameters. If no documentation exists, it returns "No documentation found."

Syntax of help()

help([object])

Parameters:

Returns: It does not return any value, it simply prints the documentation to the console. If you try to assign its output to a variable, it will return None.

Examples of help()

Example 1. Getting Help on Built-in Functions

Python
Output
Help on built-in function print in module builtins:

print(*args, sep=' ', end='\n', file=None, flush=False)
    Prints the values to a stream, or to sys.stdout by default.

    sep
      string inser...

Explanation: help(print) shows its parameters (value, sep, end, file, flush) and their default values. The function prints values to sys.stdout by default, separates them with sep, ends with end, writes to a specified file and can force flushing with flush.

Example 2. Help on user-defined classes

Python
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 ...

Explanation: Helper class has an __init__ method with a docstring and a print_help method that prints a description. help(Helper) shows class details, while help(Helper.print_help) displays method-specific info.

Example 3. when no documentation is available

Python
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

Explanation: help("GeeksforGeeks") call attempts to find documentation for the string "GeeksforGeeks". Since no such module or keyword exists, it returns "No Python documentation found", suggesting help() for interactive help or help(str) for string-related documentation.

Example 4. If a string is given as an argument

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

Example 5. Using __doc__ for documentation

Python
def fun():
    """This function demonstrates docstrings."""
    return None

print(fun.__doc__)

Output
This function demonstrates docstrings.

Explanation: fun() has a docstring describing its purpose. Calling fun.__doc__ retrieves and prints this docstring.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4