The first 8.19 __doc__ access using Python documentation string (DocStrings)

Creative Commons License Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )

__doc__ special variable for viewing help categories, functions, modules, which help information is stored in the document string.
First, the character string on the document
on the document mentioned many chapters before the string, the string for the document DocStrings documentation program, as part of the program code is embedded, so that the help information to be part of the program, the document easier helper easy to understand, easy to use and maintain.
Document string using one pair of three single quotes' '' or a pair of three double quotes "" "to enclose a text description and not assigned to a variable (if it is a single line and is itself without quotes, single quotes may be and quotation marks), it will be ignored when the code is executed, but will be placed and where the interpreter identified class, function or module doc attribute string usually document the following aspects:

  1. The beginning of the module, the entire module as described in the document;
  2. def statement function / method is defined between the body of the function, a function / method described;
  3. Between class body, after the class definition for the class description of the class statement.
    Recommended Python docstring format:
    file string is a multi-line strings, its first line begins with a capital letter, the end of the period. The second line is blank, starting from the third row is described in detail. Documents string two three quotes must be the same indentation indented code policy.

Second, the use __doc__ access the document string
can use the "class name. DOC ", "function name. DOC ", "module name. DOC " View classes, functions, document string module, make sure when you view all the relevant definitions It has been performed or loaded.
Third, the case
Here Insert Picture Description
noted that the yellow mark portion, the first two are indented, followed by a description of the difference output repr and str, with particular reference to "the similarities and differences of 8.17 Python __repr__ __str__ methods and methods, built-in repr and str Comparative analysis " .

This section introduces the definition and use of Python documentation strings as well as access methods, documentation strings is a very useful tool to help document, very much in line Python style. Please comply with the definition of the practice documentation string.

Old ape Python, with the old ape learn Python!
Blog address: https: //blog.csdn.net/LaoYuanPython

welcome to point praise, attention and processing comments!

Guess you like

Origin blog.csdn.net/LaoYuanPython/article/details/94748579