(Python基础教程之三)Python代码中添加注释

  1. Python 基础教程
  2. 在 SublimeEditor 中配置 Python 环境
  3. Python 代码中添加注释
  4. Python 中的变量的使用
  5. Python 中的数据类型
  6. Python 中的关键字
  7. Python 字符串操作
  8. Python 中的 list 操作
  9. Python 中的 Tuple 操作
  10. Pythonmax()和 min()–在列表或数组中查找最大值和最小值
  11. Python 找到最大的 N 个(前 N 个)或最小的 N 个项目
  12. Python 读写 CSV 文件
  13. Python 中使用 httplib2–HTTPGET 和 POST 示例
  14. Python 将 tuple 开箱为变量或参数
  15. Python 开箱 Tuple–太多值无法解压
  16. Pythonmultidict 示例–将单个键映射到字典中的多个值
  17. PythonOrderedDict–有序字典
  18. Python 字典交集–比较两个字典
  19. Python 优先级队列示例
  20. python 中如何格式化日期
  21. 30 分钟 Python 爬虫教程
  22. 爬虫下载网页视频 (video blob.html)

在Python(或任何其他编程语言)中,注释用于解释源代码。注释描述了代码,这有助于将来维护应用程序。

python中的注释

# prints 4

print(2 + 2)

print(2 + 3) # prints 5

"""

prints the sum of

two numbers which are 2 and 2

"""

print(2 + 2)

Python中的注释类型

Python支持编写简单的单行注释以及多行注释。

单行注释

一个简单的单行注释将以井号(#)字符开头。Python运行时会忽略#字符后写的任何文本,并将其视为注释。

单行注释

# This is a simple comment

print(2 + 2)

print(2 + 3) # prints 5

多行注释

Python没有什么特别的东西可以写多行注释。要编写它,我们可以编写多个单行注释。

我推荐这种形式的评论。

多行注释

# This statement

# prints the sum of

# two numbers which are 2 and 2

print(2 + 2)

我们可以利用未分配给变量的多行字符串文字(使用_三引号_)。Python会忽略未分配给任何变量的字符串文字,因此它不会影响程序执行。

Un-assigned string literal

"""

This statement

prints the sum of

two numbers which are 2 and 2

"""

print(2 + 2)

将有关在python中编写注释的问题交给我。

学习愉快!

posted on 2020-05-02 17:57  Java码界探秘  阅读(904)  评论(0)    收藏  举报

导航