What is the help() function in Python?
Python help() function
In Python, the help() function is used to get information or details about a function, class, keyword, module, and so on.
Syntax
help(object)
Parameter values
- Object: This parameter value represents the object that is passed to the
help()function.
Note: The interactive help utility starts up on the console if the
help()function is used without an argument.
Suppose we have a Python code with a function and we need information on what that function does. In this case, we will find the help() function to be quite useful.
Let’s look at the code example given below to better understand the help() function.
Examples
#create my_func() functiondef my_func(a,b):result = a * (b **3)return resultprint("Using help() to get info on my_func():")help(my_func)
Explanation
-
Lines 2–4: We create a function called
my_functhat takes two parameters. Next, we assign the computation result to a new variable calledresult. Finally, the function returns a value. -
Line 6: We use the
print()statement to display a message. -
Line 7: We use the
help()function to obtain details about themy_func()function.
Another example involves the use of the help() function to get information on a certain keyword:
# Using help() to get info on list keywordhelp(list)
Note: The object parameter for the
help()function is optional.