
上QQ阅读APP看书,第一时间看更新
3.1.3 注释语句
为了提高程序的可读性,通常在程序的适当位置加上一些注释,起到备注的作用。团队合作的时候,个人编写的代码经常会被多人调用,为了让别人容易理解,使用注释是非常有效的。一个好的程序,为代码加注释是必须要做的,但对于大家都明白的代码不需要加注释。
Python的注释有多种,有单行注释和多行注释。
1.单行注释
单行注释的语法格式为:

#符号右边的任何数据都会被忽略,注释语句不参与程序的执行。
若注释独占一行,则#符号顶头,#后空1格后写注释。若是行尾注释,#与前面的代码空2格,#号后空1格写注释。
【例3-4】 单行注释示例。

2.多行注释
多行注释的语法格式为:

多行注释用三个单引号'''或者三个双引号"""将注释括起来。
【例3-5】 多行注释示例。

不推荐使用多行注释,推荐每一行用一个#。