如何将描述代码的文本添加到Python源文件中?

时间:2009-10-23 15:24:33

标签: python

在Python中编写代码时,如何编写旁边的代码来解释代码的作用,但哪些代码不会影响代码呢?

3 个答案:

答案 0 :(得分:17)

我认为你在谈论comments

有一些简单的评论,以#开头:

return sys.stdin.readline()       # This is a comment

还有Docstrings,它记录了模块,类,方法和函数:

def getline():
    """This is a docstring"""
    return sys.stdin.readline()

与许多其他语言不同,Python没有多行注释语法(尽管文档字符串可以是多行的)。

答案 1 :(得分:2)

写评论? Python评论以#开头。

答案 2 :(得分:2)

你的意思是评论?在评论之前使用#字符。

http://en.wikibooks.org/wiki/Python_Programming/Source_Documentation_and_Comments

# This is a comment
print("Hello comment!")
相关问题