What is prefered: 'string' or "string"? (Should be in PEP8 ?)

Petr Prikryl Answer.via.news.please.prikrylp at nospam_skil.cz
Tue Apr 23 06:43:00 EDT 2002


Hi,

Being quite new to Python -- is there any preference of
single or double quotes when writing strings?  I am thinking
about cases when both may be used, not when I need to
include the alternative inside the string.

In other words, should I prefer writing:
    s1 = 'first string'
or
    s2 = "second string"

In yet other words, should I prefer the Pascal look of
the strings or the C/C++ look of the strings?

For me, single quotes look less noisy in the source
text (yes I work with C++, but there you have no choice).
Also, Python returns single quotes as the result of repr():

>>> print repr("double")
'double'
>>> print repr('single')
'single'

On the other hand, when the Python code is occasionally
to be converted to C/C++ code, then double quotes
may be appreciated.

While I do not consider this a problem for me (I can sleep
quite well), I think that proposing some prefered way
could make the look of Python sources more similar
each other, i.e. slightly more understandable.  I guess
that it may be important for beginners.  The experienced
user often have reasons to use both styles.

Should this be the part of the Python Style Guide (PEP8)?
I think that it would be nice to add some explanation on this
theme even when there is no prefered way.

Thanks for your opinions,
  Petr

--
Petr Prikryl (prikrylp at skil dot cz)








More information about the Python-list mailing list