
上QQ阅读APP看本书,新人免费读10天
设备和账号都新为新人
1.4 学语言先学注释
开发者最怕的是什么,就是给程序写注释,比写注释更可怕的是别人的代码不写注释。多么有趣的逻辑。
如果想提高程序的可读性,是离不开程序注释的。在公司里,一个程序、一个项目、一个产品包含成千上万个代码块,如果不写注释,你会成为被团队声讨的对象。
1.4.1 注释符号
在Python中,使用#符号表示单行注释,也就是说#符号后面的内容会被Python解释器(直译器)忽略,不予运行。
例如,在一个Python项目自动生成的代码中,包含了很多单行注释:

注释符号#可以放在代码上面,也可以放在代码右侧,例如:

1.4.2 多行注释
如果想要写多行注释,可以在每行中都用一个#符号,也可以使用3个双引号“"""”实现,例如:


对于Python语言,使用3个单引号“'''”效果也是一样的:

关于三引号的使用,在后续讲解字符串时还会出现,此处理解为多行注释即可。