当前位置:网站首页>2. # code comments

2. # code comments

2022-08-01 03:07:00 Andy Python

2. Python # 代码注释

1. 什么是代码注释

Code comments are comments on the code.
It is equivalent to annotating a Chinese definition for an English word.

【温馨提示】注释是给程序员自己看的,will not be executed by the computer.

【示例】

# 用printThe function outputs an integer
print(520)
520

上述代码中的第1行是注释,to explain the2行代码.

2. 注释语法

A one-line comment statement usually consists of 4部分组成:

1.#
2.空格
3.注释内容
4.注释位置

【解析】

1
1

1.是注释符号,at the beginning of a comment line;
2.#后面有一个空格,The spaces are there to make the comments look nicer;
3.Write comments;
4.Comments can be on the previous line of code,Also at the end of the code.

2
2

3. 注释位置

1. The comment is on the previous line of the code

# 用printThe function outputs an integer
# Note that parentheses should be used in English parentheses
print(520)

【终端输出】

520

2. Comments are at the end of the code

print(520)  # 用printThe function outputs an integer

【终端输出】

520

4. 课堂练习

自己动手用print( )The function outputs today's date,and write a line comment for it.

原网站

版权声明
本文为[Andy Python]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/213/202208010231308125.html