The help()
function is used to get access to the interactive help system. We can use it to find information about built-in functions, data types, keywords, modules, and even the current Python interpreter environment. The function can especially be useful if you are new to Python as it can help you to quickly find out what a certain function or keyword does.
There are two ways to use the help()
function.
help() help(argument)
copy
Calling the function using the first syntax( without any argument) pauses the interpreter and starts an interactive help session. In the session, we can type the name of the function, class, keyword, object, etc eg while or a string containing the name e.g "while" and the interpreter will display the relevant help text.
In the second approach,we pass the name when calling the function and the interpreter simply prints the help text without starting an interactive help session.
What type of objects can we find help on?
- Modules: Use help(module) to get information about a module.
- Classes and Functions: Use help(class) or help(function) to get information about a specific class or function, respectively.
- Keywords: Use help('keyword') to get information about a keyword.
- Topics: Use help('topics') to get information about topics such as the Python tutorial or how to use the help system.
- Symbols: Use help('symbols') to get information about symbols such as operators or special characters.
- Packages: Use help('package') to get information about a package.