Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

  1. three single quotes:

    ''' Comment goes here '''   
  2. three double quotes:

    """ Comment goes here """ 

Is there any subtle difference in the way doc string could be formatted later while generating docs?

like image 259
prashu Avatar asked Oct 26 '12 05:10

prashu


People also ask

When would you wrap a string in triple single quotes or triple double quotes?

To create strings that span multiple lines, triple single quotes ''' or triple double quotes """ are used to enclose the string. ''' This string is on multiple lines within three single quotes on either side.

What does Triple single quote mean?

Python's triple quotes comes to the rescue by allowing strings to span multiple lines, including verbatim NEWLINEs, TABs, and any other special characters. The syntax for triple quotes consists of three consecutive single or double quotes.

What is the difference between using single and double quotation marks?

General Usage Rules In America, Canada, Australia and New Zealand, the general rule is that double quotes are used to denote direct speech. Single quotes are used to enclose a quote within a quote, a quote within a headline, or a title within a quote.


1 Answers

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

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.

like image 140
BrenBarn Avatar answered Sep 19 '22 20:09

BrenBarn