# 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."
注释不是给机器运行的,而是给人看的。
给一段代码加上注释,是为了解释清楚这段代码要注意的地方或者这段代码的功能。
调式程序时,也可使用井号将某些代码临时注释。
在python中使用井号#为代码做注释, python解释器遇到井号#即忽略。
注释可以单独一行,也可跟在一句代码的后面。
如果使用中文注释:#这是注释
print "This will run." #这也是注释
会出现如下异常:E:\python\examples\ex2>python ex2.py
File "ex2.py", line 1
SyntaxError: Non-ASCII character '\xe8' in file ex2.py on line 1,but no encoding
declared; see http://python.org/dev/peps/pep-0263/ for details
第一行是