Python help () function usage

Source: Internet
Author: User

The help function is a built-in function of python (python built-in functions can be called directly without the need for import). It is a built-in function of python and can be used at any time. What can the help function do, how to use the help function to view the usage of the function in the python module, and what issues need to be paid attention to when using the help function, which is briefly described below.

I. Functions of the help () function
When writing code using python, python built-in functions or modules are often used. The usage of some uncommonly used functions or modules is not very clear. At this time, you need to use the help function to view help.
Note that the help () function is a detailed description of the function or module usage, and the dir () function is used to view the operation methods in the function or module, the output is the method list.
Ii. How to use the help function to view the usage of functions in the python Module
Enter parameters in brackets for help (). The procedure is simple. For example:
Copy codeThe Code is as follows: >>> 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.

3. Use the help function to view help instances

When writing the help () function usage method, you should fill in parameters in brackets. Pay attention to the parameter format here:

1. view the help of a module
Copy codeThe Code is as follows: >>> help ('sys ')
Then it opens the help document for this module.
2. view the help of a data type
Copy codeThe Code is as follows: >>> help ('str ')
Returns the string method and detailed description.
Copy codeThe Code is as follows: >>> a = [1, 2, 3]
>>> Help ()
At this time, help (a) will open the list Operation Method
Copy codeThe Code is as follows: >>> help (a. append)
The list append method help is displayed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.