Python Learning note 010--function document string

Source: Internet
Author: User

The function document string documentation string (docstring) is the string that is used to interpret its interface at the beginning of the function. In a nutshell: Help documentation

    1. The underlying information for the containing function
    2. Introduction to functions containing functions
    3. Contains the type of each parameter, using information such as
    4. is an important part of the interface design.
    5. Note: A good interface is not a simple, clear representation of the function, which means that the function also has a space for optimization improvement

Use of function documents

    1. It must be in the first line of the function, and it is possible to verify that the explanatory note precedes it, but the best function document appears in the first line
    2. A multiline string with a three-quote annotation (or, of course, a line), in which a multiline annotation ("" ") or (" "" "" ") can be implemented with three quotation marks.
    3. The first line of the function document generally outlines the main functions of the function, the second line is empty, and the third line is described in detail.

View mode

    1. In interactive mode, you can use Help to view the function, which will jump to the help screen and need to enter the Q exit interface.
    2. Using the __doc__ property view, the Help document text for this method is displayed directly on the interactive interface.

Examples Show

def Test ():     " "         function Name:        Test Function: Testing        parameters: No        return value: None     '    print("  Function output Successful ") test ()

Enter in interactive mode

Import>>> Help (Day10.test)

Finally, the help screen shows the following

Press the Q key to exit

Also access in interactive mode

Import Day10 Print (Day10.test. __doc__         function Name:        Test Function: Testing        parameters: No        return value: None    

As follows

The Help document is displayed directly under it.

Python Learning note 010--function document string

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.