Python help() function with example
This tutorial will teach you about the Python help() function. The help() function displays the documentation of an object. This is a built-in function and prints a help page when it is called. Let’s understand it with a few examples.
The syntax for the help() function is as follows:
help([object])
As you can see, this function takes an object as the input parameter. It prints the documentation of the object passed in the function.
help(int)
Executing the above code will print a help page on the console containing documentation of object int. If you keep pressing enter it will show more about the documentation of int object.
Now, let’s create a Python class and then use the help() function to get the help page on it.
class AA: def __init__(self): #Intialisation pass def method(self): #method inside the class pass help(AA)
Output:
Help on class AA in module __main__: class AA(builtins.object) | Methods defined here: | | __init__(self) | Initialize self. See help(type(self)) for accurate signature. | | method(self) | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined)
If we pass a string containing the name of an object, then help() function will print the help on that object. See the code below.
help('list') help('str') help('int')
If we do not pass any argument in help(), then it will start Python help utility on the console as shown below in the program.
help()
Output:
help>
We can give any object name here and its documentation would be printed.
help> print
This will print the documentation of the print object.
Thank you.
Also read: Python next() Function with examples
Leave a Reply