三重单引号和三重双引号的文档字符串有什么区别? [英] What's the difference on docstrings with triple SINGLE quotes and triple DOUBLE quotes?

查看:287
本文介绍了三重单引号和三重双引号的文档字符串有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道两种编写Python Docstrings(__doc__)的方式之间的区别:

I was just wondering what is the difference between two ways of writing Python Docstrings (__doc__):

  1. 三个单引号:

  1. 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.

    这篇关于三重单引号和三重双引号的文档字符串有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆