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

Steve Holden sholden at holdenweb.com
Tue Apr 23 08:27:14 EDT 2002


"Philipp Lenssen" <phil at mrinfo.de> wrote in message
news:aa3fbk$pfb$1 at swifty.westend.com...
> "Petr Prikryl" <Answer.via.news.please.prikrylp at nospam_skil.cz> wrote in
> message news:aa3dti$n0$1 at news.nextra.cz...
> >..
> > In other words, should I prefer writing:
> >     s1 = 'first string'
> > or
> >     s2 = "second string"
> >..
>
> For XHTML string output, I prefer single quotes because I don't have to
> escape double-quotes within the string, e.g.:
> s += '<img src="..." alt="" />'
>

For XHTML and HTML output you would find the triple-quoted forms much
easier. Then you can use EITHER quotes in your output, and include newlines
as well, as in:

s = """%s
<img src="..." alt="A comment">""" % s

regards
 Steve
--

home: http://www.holdenweb.com/
Python Web Programming:
http://pydish.holdenweb.com/pwp/








More information about the Python-list mailing list