Difference between three single quotes and three double quotes docstrings in python

I'm just wondering what the difference is between the 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 how the doc string can be formatted later when creating documents?

+7
source share
3 answers

Not. They are identical. The only difference is that the first may contain a sequence of three captive double quotes, and the second may contain a sequence of three captive single quotes. (In other words, since the delimiters are different, there is a slight difference in which characters you can use inside them.)

Docstrings are just regular strings, and in Python there is no difference between different line breaks, except of course you cannot use a line break inside a string.

+10
source

Choose any style you want. Personally, I use single quotes wherever I can in Python.

The documentation states:

 "String literals can be enclosed in matching single quotes (') or double quotes (")." 

It doesn’t matter which one you decide to use. The important thing is that you stick to your decision . It’s good practice to choose a style and stick to it.

+4
source

It does not really matter. But for what the examples in PEP 257 - Docstring Conventions are worth , everyone uses "" "triple double quotes" ".

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

+2
source

All Articles