问题描述
我只是想知道两种编写Python Docstrings(__doc__
)的方式之间的区别:
I was just wondering what is the difference between two ways of writing Python Docstrings (__doc__
):
-
三个单引号:
three single quotes:
'''
Comment goes here
'''
三个双引号:
three double quotes:
"""
Comment goes here
"""
以后生成文档时格式化文档字符串的方式是否存在细微差别?
Is there any subtle difference in the way doc string could be formatted later while generating docs?
推荐答案
否.他们是一样的.唯一的区别是,第一个可以包含三个未转义的双引号的序列,而第二个可以包含三个未转义的单引号的序列. (换句话说,由于分隔符不同,因此您可以在其中使用哪些字符略有不同.)
No. They are the same. The only difference is that the first one can contain a sequence of three unescaped double quotes, while the second can contain a sequence of three unescaped single quotes. (In other words, because the delimiters are different, there is a slight difference in what characters you can use inside them.)
文档字符串只是常规字符串,在Python中,不同的字符串定界符之间没有区别,除了,当然,您不能在字符串内部使用字符串定界符.
Docstrings are just regular strings, and in Python there is no difference between the different string delimiters, except that, of course, you can't use the string delimiter inside the string.
这篇关于三重单引号和三重双引号的文档字符串有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!