
上QQ阅读APP看书,第一时间看更新
1-9 程序注释
程序注释主要功能是让你所设计的程序可读性更高,更容易了解。在企业工作,一个实用的程序可以很轻易超过几千或上万行,此时你可能需设计好几个月,程序加上注释,可方便你或他人,未来较方便地了解程序内容。
1-9-1 注释符号#
不论是Python Shell直译器或是Python程序文件中,“#”符号右边的文字,皆是称程序注释,Python语言的直译器会忽略此符号右边的文字。可参考下列实例。
实例1:在Python Shell窗口注释的应用1,注释可以放在程序叙述的右边。

实例2:在Python Shell窗口注释的应用2,注释可以放在程序叙述的前面。

程序实例ch1_2.py:重新设计ch1_1.py,为程序增加注释。

Python程序左边是没有行号的,这是笔者为了读者阅读方便加上去的。
1-9-2 三个单引号或双引号
如果要进行大段落的注释,可以用三个单引号或双引号将注释文字包夹。
程序实例ch1_3.py:以三个单引号当作注释。

上述前5行是程序注释。
程序实例ch1_4.py:以三个双引号当作注释。

上述前5行是程序注释。