The help function in Python is utilized to obtain assistance regarding the object that is provided as an argument during its invocation. It accepts an optional parameter and returns relevant help information. If no argument is supplied, it displays the Python help console. Internally, it invokes Python's built-in help function.
Python help Function Syntax
It has the following syntax:
help(object)
Parameters
- object: It may refer to any object that we seek assistance with.
Return
It returns the object's info.
Different Examples for Python help Function
Let’s examine a few instances of the help function to gain insights into its capabilities.
Python help Function Example 1
Let's consider an example to illustrate the functionality of the Python help function.
# Python help() function example
# Calling function
info = help() # No argument
# Displaying result
print(info)
Output:
Welcome to Python 3.5's help utility!
Python help Function Example 2
Let's consider an additional example to illustrate the Python help function.
# Python help() function example
# Calling function
info = help(1) # integer value
# Displaying result
print(info)
Output:
Help on int object:
class int(object)
| int(x=0) -> integer
| int(x, base=10) -> integer
|
| Methods defined here:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __and__(self, value, /)
| Return self&value.
Python help Function Example 3
When the object in question is a list, it initializes the list module along with its associated class. Observe the resulting output.
# Python help() function example
# Calling function
info = help(list) # integer value
# Displaying result
print(info)
Output:
Help on class list in module builtins:
class list(object)
| list() -> new empty list
| list(iterable) -> new list initialized from iterable's items
|
| Methods defined here:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
| Return key in self.
|
| __delitem__(self, key, /)
| Delete self[key].
Python help Function Example 4
In the absence of any assistance or information, a message is displayed in the console, and the function returns None.
# Python help() function example
# Calling function
info = help("Example") # integer value
# Displaying result
print(info)
Output:
No Python documentation found for 'Example'.
Use help() to get the interactive help utility.
Use help(str) for help on the str class.
None