如何在Python源文件中添加代码描述文字?
在写Python代码的时候,怎么能在代码旁边写一些解释,告诉别人这段代码在干什么,但又不影响代码的运行呢?
3 个回答
2
想写个注释吗?在Python里,注释是用#
开头的。
2
你是说注释吗?在你的注释前面加上#这个符号。
http://en.wikibooks.org/wiki/Python_Programming/Source_Documentation_and_Comments
# This is a comment print("Hello comment!")
17
我想你是在说注释吧?
有一种普通的注释,它是以#
开头的:
return sys.stdin.readline() # This is a comment
还有一种叫做文档字符串(Docstrings),它用来记录模块、类、方法和函数的信息:
def getline():
"""This is a docstring"""
return sys.stdin.readline()
跟很多其他编程语言不同,Python没有多行注释的语法(不过文档字符串可以是多行的)。