apostrophe or double quote?

Sion Arrowsmith siona at chiark.greenend.org.uk
Wed Feb 8 08:56:42 EST 2006


Steve Holden  <steve at holdenweb.com> wrote:
>Huy wrote:
>> I've been unable to find information clarifying this but.  What is the
>> difference between 'somestring' and "somestring"?
>It's just easier to have two permitted string quotes. That way, if your 
>string has an apostrophe in it you can say
>
>     s = "it's"
>
>and if it has a double quote in it you can say
>
>     s = 'The double quote (") rules'
>
>So there's really no difference at all. You can also use escaping to 
>achieve the same end:
>
>     s = "The double quote (\") rules"
>
>if you prefer.

Or triple quoting:

    s = """The double quote (") rules"""


I've seen someone around here use 'somestring' for internal values
(dict keys and the like) and "somestring" for values being shown to
the user, so it's easy(ish) to tell what may need translating or
can otherwise safely be changed. I like this convention (provided
it remains a convention).

-- 
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |    -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump



More information about the Python-list mailing list