Home > Article > Backend Development > Python's help function usage
The help function is a built-in function of python. We have introduced what a built-in function is in the basic knowledge of python. It is a function that comes with python and can be used at any time. What the help function can do, how to use the help function to view the usage of functions in python module learning, and what issues need to be paid attention to when using the help function, let’s briefly talk about it below.
What can the help function do
When using python to write code, python is often used to call functions, built-in functions or modules, some uncommon functions or The purpose of the module is not very clear. At this time, you need to use the help function to view the help.
It should be noted here that the help() function is to view a detailed description of the purpose of the function or module, while the dir() function is to view the operation methods within the function or module, and the output is a method list.
How to use the help function to view the usage of functions in the python module
Fill in the parameters in help() brackets. The operation method is very simple.
What issues need to be paid attention to when using the help function to view help?
When I wrote how to use the help() function, I said that the parameters should be filled in in parentheses, so pay attention to the form of the parameters here:
1. View the help of a module
>>>help('sys')
Then it will open the help document of this module
2. View the help of a data type
>>>help('str')
Return characters String methods and detailed instructions
>>>a = [1,2,3] >>>help(a)
At this time, help(a) will open the operation method of the list
>>>help(a.append)
The help for the append method of the list will be displayed.
Example extension:
How to use the help function to view the usage of functions in the python module
Fill in the parameters in help() brackets, the operation method is very simple . For example:
>>> help('dir') Help on built-in function dir in module builtins: dir(...) dir([object]) -> list of strings If called without an argument, return the names in the current scope. Else, return an alphabetized list of names comprising (some of) the attribut es of the given object, and of attributes reachable from it. If the object supplies a method named __dir__, it will be used; otherwise the default dir() logic is used and returns: for a module object: the module's attributes. for a class object: its attributes, and recursively the attributes of its bases. for any other object: its attributes, its class's attributes, and recursively the attributes of its class's base classes.
Recommended tutorial: "Python Tutorial"
The above is the detailed content of Python's help function usage. For more information, please follow other related articles on the PHP Chinese website!