help()
functionIn Python, the help()
function is used to get information or details about a function, class, keyword, module, and so on.
help(object)
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.
#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)
Lines 2–4: We create a function called my_func
that takes two parameters. Next, we assign the computation result to a new variable called result
. 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 the my_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.