Home>

I'm learning Python, but I don't understand the documentation string.
I would appreciate your reply and explanation.

Excerpts you do n’t understand 4.7.6. Documentation string at the above URL

The Python parser does not strip indents from multi-line Python string literals, so any document processing tool must strip indents as needed. This processing is performed according to the following rules. The first non-blank line after the first line determines the amount of indentation for the entire document. (The first line is usually next to the quote that starts the string, so the indent does not appear in the string literal.) This indent amount and the"Will be stripped from the beginning of the line. Don't write a line with a small amount of indentation, but if it does, all the leading whitespace is stripped off. Indentation white space is checked for equality after expanding tab characters (usually as 8 character spaces).

Here is an example of a multi-line documentation string:

>>>def my_function ():
... "" "Do nothing, but document it.
...
... No, really, it doesn't do anything.
... "" "
... pass
...
>>>print (my_function .__ doc__)
Do nothing, but document it.
    No, really, it doesn't do anything.
What do you know?

① The first non-blank line after the first line that determines the amount of indentation for the whole document is
Is it correct in the pass line of the above source code?

② "This indentation"equal"space is stripped from the beginning of every line in the string." Since the pass line has an indent of 4 spaces, does it mean that 4 spaces will be cut off on other lines?

③ "You can check if the indent spaces are equal in size after expanding the tab character (usually as an 8-character space)"
I don't understand this at all.
Where did the number 8 come from?
Also, when is it done to check if indentation whitespaces are equal in size?

The above is a detailed matter, but I asked a question because there are no doubts.

  • Answer # 1

      

    ① The first non-blank line after the first line that determines the amount of indentation for the whole document is
      Is it correct in the pass line of the above source code?

    Wrong.No, really, it doesn't do anything.

      

    ② "This indentation"equal"space is stripped from the beginning of every line in the string."   Since the pass line has an indent of 4 spaces, does it mean that 4 spaces will be cut off on other lines?

    Yes. The "document processing tool" must "strip off" the white space according to the rules.

      

    ③ "You can check if the indent spaces are equal in size after expanding the tab character (usually as an 8-character space)"
      I don't understand this at all.
      Where did the number 8 come from?
      Also, when is it done to check if indentation whitespaces are equal in size?

    8 is just a convention that treats the tab character as eight spaces.