Python help() function Examples
Simple help() Program
In this example, we are using help() without any object to access documentation in Python.
Python3
help () |
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 ( "w3wiki" )) |
No Python documentation found for 'w3wiki'. 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' ) |
No Python documentation found for 'gfg'. Use help() to get the interactive help utility. Use help(str) for help on the str class.
Help function in Python
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.
Contact Us