Python comments: 1. Use [#] in Python to indicate single-line comments. Single-line comments can be placed as a separate line above the commented line of code, or after a statement or expression; 2. Python Use three single quotes or three double quotes to indicate multi-line comments.
The operating environment of this tutorial: Windows 7 system, python version 3.9, DELL G3 computer. This method is suitable for all brands of computers.
Python comments:
1. Single-line comments (line comments)
Used in Python # represents a single line comment. Single-line comments can be placed as a separate line above the line of code being commented, or after a statement or expression.
# 这是单行注释
When a single-line comment is placed as a separate line above the commented line of code, in order to ensure the readability of the code, it is recommended to add a space after # and then add the comment content .
When a single-line comment is placed after a statement or expression, in order to ensure the readability of the code, it is recommended that there be at least two spaces between the comment and the statement (or comment and the expression).
2. Multi-line comments (block comments)
When there is too much comment content and one line cannot be displayed, you can use multi-line comments. In Python, use three single quotes
or three double quotes
to indicate multi-line comments.
''' 这是使用三个单引号的多行注释 ''' """ 这是使用三个双引号的多行注释 """
3. Note that
The more comments, the better. For code that is self-explanatory, there is no need to add comments.
For complex operations, corresponding comments should be written before starting the operation.
For code that is not self-explanatory, comments should be added after the code.
Never describe code. Generally, people who read code know the syntax of Python, but they just don’t know what the code is doing.
Related free learning recommendations: python video tutorial
The above is the detailed content of what are python annotations. For more information, please follow other related articles on the PHP Chinese website!