what are python annotations

coldplay.xixi
Release: 2023-01-03 09:26:43
Original
77897 people have browsed it

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.

# 这是单行注释
Copy after login

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.

'''
这是使用三个单引号的多行注释
'''
"""
这是使用三个双引号的多行注释
"""
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template