What's the difference on docstrings with triple SINGLE quotes and triple DOUBLE quotes?

前端 未结 3 1638
梦毁少年i
梦毁少年i 2021-01-01 16:08

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

  1. three single quotes:

    \'\'\         
    
    
            
3条回答
  •  星月不相逢
    2021-01-01 17:02

    The informational document PEP 257 -- Docstring Conventions recommends to use """triple double-quotes""" for consistency, and all their examples show the same:

    For consistency, always use """triple double quotes""" around docstrings. Use r"""raw triple double quotes""" if you use any backslashes in your docstrings. For Unicode docstrings, use u"""Unicode triple-quoted strings""".

    Whether to use single quotes or double quotes is only a stylistic issue in practice. There will be no difference in formatting when generating and publishing docs from these strings.

提交回复
热议问题