Ex2 Comment

注释天然重要

在每一本有自尊的编程书里,必然提到如何给程序写注释。入门之初,都会有人告诉你,写代码要有注释。就像是写数学证明时候,不光要用符号,还要用人类语言补充内容。如果一段代码没有注释,几个月后你再看代码,很可能都认不出来是代码的含义,以及当初为什么这么写了。

Python里的注释用法

对于Python语言,“#”后面的内容是注释。如果要注释多行,每行首部,使用“#”。示例2的代码如下:

1
2
3
4
5
6
# A comment, this is so you can read your program later.
# Anything after the # is ignored by python.
print "I could have code like this." # and the comment after is ignored.
# You can also use a comment to "disable" or comment out a piece of code:
# print "This won't run."
print "This will run."

这段代码的结果如下:

源码里,最后一行,没有对齐,所以显示效果跟Zed给出的有区别。

Licensed under CC BY-NC-SA 4.0
使用 Hugo 构建
主题 StackJimmy 设计