Difference between double and single quotes
François Pinard
pinard at iro.umontreal.ca
Tue Aug 1 08:38:17 EDT 2000
[pauljolly at my-deja.com]
> Please can someone tell me whether Python distinguishes between double
> and single quotes in any way? This was brought to my attention by a
> friend who queried my use of double and single quotes, saying that in
> the UNIX shell a distinction is made.
The Unix shell and Perl do a distinction, indeed, but Python does not.
Being myself anal and needing a reason and motive for everything, I
gave myself an artificial rule which I try to follow, but this is only a
convention of mine, Python does not force me into anything. If the string
is to be ultimately read by a human, I use "", when if the string is meant
for the machine or algorithm mainly, I use ''. (This is not the same
thing as the translatability of a string, which I mark by other means).
Even if slightly fuzzy, this convention is best for me. I do prefer ''
over "" in general as I find the former more readable, but the fact that
the apostrophe is commonly used in human texts make "" more adequate.
I usually prefer using \" within " strings and \' within ' strings, than
to break my own convention.
--
François Pinard http://www.iro.umontreal.ca/~pinard
More information about the Python-list
mailing list