Why is """ the preferred delimiter for multi-line strings?
Why """, not '''?
Collapse
This topic is closed.
X
X
-
MartinRinehart@gmail.comTags: None -
George Sakkis
Re: Why ""&qu ot;, not '''?
On Mar 5, 9:56 am, MartinRineh...@ gmail.com wrote:Is it ? FWIW, I use single quotes whenever I can and double whenever IWhy is """ the preferred delimiter for multi-line strings?
have to (i.e. rarely).
George
-
D'Arcy J.M. Cain
Re: Why ""&qu ot;, not '''?
On Wed, 5 Mar 2008 06:56:24 -0800 (PST)
MartinRinehart@ gmail.com wrote:Where did you see that? The only place I saw it was the style guideWhy is """ the preferred delimiter for multi-line strings?
and it was only talking about docstrings. Even there they used """ as
an example but the text talked about using triple quotes as opposed to
single quotes even when it is a single line docstring. I don't think
that there is any preference for """ over ''' in general. Pick one for
consistiency.
Note however that """ can't be confused with " followed by ' as in "'A'
is the first letter of the alphabet."
--
D'Arcy J.M. Cain <darcy@druid.ne t | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
Comment
-
MartinRinehart@gmail.com
Re: Why ""&qu ot;, not '''?
D'Arcy J.M. Cain wrote:PEP 8 and 257, and you're right, they are both about docstrings.Where did you see that? The only place I saw it was the style guide
and it was only talking about docstrings.
Also, I'd never seen an example of the triple apostrophe form until I
dove
into the formal syntax specification.
Comment
-
Matthew Woodcraft
Re: Why ""&qu ot;, not '''?
<MartinRinehart @gmail.comwrote :One advantage is that a dumb syntax highlighter is more likely to copeWhy is """ the preferred delimiter for multi-line strings?
well if the content includes an apostrophe.
-M-
Comment
-
Steven D'Aprano
Re: Why ""&qu ot;, not '''?
On Wed, 05 Mar 2008 19:19:08 +0000, Matthew Woodcraft wrote:
But if the content contains double-quote marks, the "dumb syntax<MartinRinehart @gmail.comwrote :>>Why is """ the preferred delimiter for multi-line strings?
One advantage is that a dumb syntax highlighter is more likely to cope
well if the content includes an apostrophe.
highligher" is more likely to cope well if you use '''. And, let's be
realistic here, a "dumb syntax highlighter" is more likely to not cope
well with triple-quote strings *at all*.
Python treats ' and " symmetrically. There is no difference between them,
except that:
(1) to type " requires using the shift-key, typing ' does not (on English
QWERTY keyboards at least);
(2) in some typefaces " (double-quote) may be confused with '' (two
single-quotes); and
(3) they look different.
Pretty basic stuff really.
--
Steven
Comment
-
Matthew Woodcraft
Re: Why ""&qu ot;, not '''?
Steven D'Aprano <steve@REMOVE-THIS-cybersource.com .auwrote:>On Wed, 05 Mar 2008 19:19:08 +0000, Matthew Woodcraft wrote:>One advantage is that a dumb syntax highlighter is more likely to cope
>well if the content includes an apostrophe.That's right. But apostrophes are rather more common than quote marksBut if the content contains double-quote marks, the "dumb syntax
highligher" is more likely to cope well if you use '''.
in English text.
In practice they often do the right thing, what with three being an oddAnd, let's be realistic here, a "dumb syntax highlighter" is more
likely to not cope well with triple-quote strings *at all*.
number.
-M-
Comment
-
Steven D'Aprano
Re: Why ""&qu ot;, not '''?
On Wed, 05 Mar 2008 23:27:21 +0000, Matthew Woodcraft wrote:
Surely it would depend on the type of text: pick up any random EnglishSteven D'Aprano <steve@REMOVE-THIS-cybersource.com .auwrote:>>>On Wed, 05 Mar 2008 19:19:08 +0000, Matthew Woodcraft wrote:>>One advantage is that a dumb syntax highlighter is more likely to cope
>>well if the content includes an apostrophe.>>But if the content contains double-quote marks, the "dumb syntax
>highligher" is more likely to cope well if you use '''.
That's right. But apostrophes are rather more common than quote marks in
English text.
novel containing dialogue, and you're likely to find a couple of dozen
pairs of quotation marks per page, against a few apostrophes.
--
Steven
Comment
-
Matt Nordhoff
[OT] Re: Why ""&qu ot;, not '''?
Steven D'Aprano wrote:That's an idea... Write a novel in Python docstrings.Surely it would depend on the type of text: pick up any random English
novel containing dialogue, and you're likely to find a couple of dozen
pairs of quotation marks per page, against a few apostrophes.
Someone make me go to bed now.
--
Comment
Comment