Why """, not '''?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MartinRinehart@gmail.com

    Why """, not '''?

    Why is """ the preferred delimiter for multi-line strings?
  • George Sakkis

    #2
    Re: Why ""&qu ot;, not '''?

    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

    Comment

    • D'Arcy J.M. Cain

      #3
      Re: Why ""&qu ot;, not '''?

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

        #4
        Re: Why &quot;&quot;&qu ot;, not '''?



        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.

        Comment

        • Matthew Woodcraft

          #5
          Re: Why &quot;&quot;&qu ot;, not '''?

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

          -M-

          Comment

          • Steven D'Aprano

            #6
            Re: Why &quot;&quot;&qu ot;, not '''?

            On Wed, 05 Mar 2008 19:19:08 +0000, Matthew Woodcraft wrote:
            <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.
            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

            Comment

            • Matthew Woodcraft

              #7
              Re: Why &quot;&quot;&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.
              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-

              Comment

              • Steven D'Aprano

                #8
                Re: Why &quot;&quot;&qu ot;, not '''?

                On Wed, 05 Mar 2008 23:27:21 +0000, Matthew Woodcraft wrote:
                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.
                >
                >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

                Comment

                • Matt Nordhoff

                  #9
                  [OT] Re: Why &quot;&quot;&qu ot;, not '''?

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

                  Comment

                  Working...