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
- The underlying information for the containing function
- Introduction to functions containing functions
- Contains the type of each parameter, using information such as
- is an important part of the interface design.
- 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
- 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
- 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.
- 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
- 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.
- 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