[英]A Single Set of Double Quotes for Python Comments?
在审查edX.org上的在线CS188.1x类中使用的一些代码(由教师编写的代码)时,我注意到重复使用一组双引号(如可能在str附近使用)用作注释。
我之前没有见过这个,也没有在PEP8中提到我能找到的,但它似乎确实很好。 任何人都可以开导我吗?
这是一个例子:
class SomeClass():
"""
Some docstring info, using standard 'triple double quotes'
"""
def __init__(self):
"This is the comment style to which I'm referring."
some.code = foo # Here's a normal inline comment
def bar(self, item):
"Here is another example of the comment style"
return wtf
docstring是任何字符串文字,它作为类,方法,函数或模块中的第一个语句出现。 在风格上,使用三重引号格式以允许更长,更好格式化的文档字符串,并引起对它们的注意以便于参考,但是任何字符串都符合条件。
文档字符串与注释不同,因为注释与程序的执行完全无关,而文档字符串在运行时通过访问对象的__doc__
变量可用。
那只是文档。 这是一个很好的设计建议。 例如,如果你在python shell中加载该类,你可以调用一个help(bar)
,你会得到"Here is another example of the comment style"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.