![]() |
VOOZH | about |
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:
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."
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.
Example 1. Getting Help on Built-in Functions
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
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
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
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
This function demonstrates docstrings.
Explanation: fun() has a docstring describing its purpose. Calling fun.__doc__ retrieves and prints this docstring.