Home >Backend Development >Python Tutorial >what are python annotations

what are python annotations

coldplay.xixi
coldplay.xixiOriginal
2021-03-02 11:25:0377933browse

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.

what are python annotations

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn