f



Why """, not '''?

Why is """ the preferred delimiter for multi-line strings?
0
3/5/2008 2:56:24 PM
comp.lang.python 77058 articles. 6 followers. Post Follow

9 Replies
1327 Views

Similar Articles

[PageSpeed] 52

On Mar 5, 9:56 am, MartinRineh...@gmail.com wrote:
> Why is """ the preferred delimiter for multi-line strings?

Is it ? FWIW, I use single quotes whenever I can and double whenever I
have to (i.e. rarely).

George
0
3/5/2008 3:11:30 PM
On Wed, 5 Mar 2008 06:56:24 -0800 (PST)
MartinRinehart@gmail.com wrote:
> Why is """ the preferred delimiter for multi-line strings?

Where did you see that?  The only place I saw it was the style guide
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.net>         |  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.
0
darcy (332)
3/5/2008 3:13:59 PM

D'Arcy J.M. Cain wrote:
> Where did you see that?  The only place I saw it was the style guide
> and it was only talking about docstrings.

PEP 8 and 257, and you're right, they are both about docstrings.

Also, I'd never seen an example of the triple apostrophe form until I
dove
into the formal syntax specification.
0
3/5/2008 4:40:15 PM
<MartinRinehart@gmail.com> wrote:
> 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.

-M-
0
3/5/2008 7:19:08 PM
On Wed, 05 Mar 2008 19:19:08 +0000, Matthew Woodcraft wrote:

> <MartinRinehart@gmail.com> wrote:
>> 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.

But if the content contains double-quote marks, the "dumb syntax 
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
0
steve9679 (1985)
3/5/2008 9:59:19 PM
Steven D'Aprano  <steve@REMOVE-THIS-cybersource.com.au> wrote:
>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.

> And, let's be realistic here, a "dumb syntax highlighter" is more
> likely to not cope well with triple-quote strings *at all*.

In practice they often do the right thing, what with three being an odd
number.

-M-
0
3/5/2008 11:27:21 PM
On Wed, 05 Mar 2008 23:27:21 +0000, Matthew Woodcraft wrote:

> Steven D'Aprano  <steve@REMOVE-THIS-cybersource.com.au> wrote:
>>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.

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.



-- 
Steven
0
steve9679 (1985)
3/6/2008 12:07:00 AM
Steven D'Aprano wrote:
> 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.

That's an idea... Write a novel in Python docstrings.

Someone make me go to bed now.
-- 
0
mnordhoff (148)
3/6/2008 1:24:10 AM
On Mar 5, 7:24 pm, Matt Nordhoff <mnordh...@mattnordhoff.com> wrote:
> Steven D'Aprano wrote:
> > 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.
>
> That's an idea... Write a novel in Python docstrings.

Or better yet, write in Python syntax.


assert len([man for man in now_alive() if
man.remembers(datetime.date(1775, 4, 18))]) <= HARDLY

lantern_count = {'land': 1, 'sea': 2}.get(british.location(), 0)
n_ch_twr.hang(Lantern() for _ in xrange(lantern_count))

if lantern_count:
    for village in middlesex:
        ride_thru(village)
        spread_alarm(village)

0
danb_83 (421)
3/6/2008 2:35:12 AM
Reply: