Strings: double versus single quotes
Tim Chase
python.list at tim.thechases.com
Tue May 19 14:36:54 EDT 2020
On 2020-05-19 20:10, Manfred Lotz wrote:
> Hi there,
> I am asking myself if I should preferably use single or double
> quotes for strings?
I'd say your consistency matters more than which one you choose.
According to a recent observation by Raymond H.
"""
Over time, the #python world has shown increasing preference
for double quotes: "hello" versus 'hello'.
Perhaps, this is due to the persistent influence of JSON,
PyCharm, Black, and plain English.
In contrast, the interpreter itself prefers single quotes:
>>> "hello"
'hello'
"""
https://twitter.com/raymondh/status/1259209765072154624
I think the worst choice is to be haphazard in your usage with a
hodgepodge of single/double quotes.
I personally use habits from my C days: double-quotes for everything
except single characters for which I use a single-quote:
if 'e' in "hello":
as in indicator that I'm using it as a single character rather than
as a string.
I don't have a firm rule for myself if a string contains
double-quotes. It doesn't happen often for me in a case where I
couldn't use a triple-quoted string or that I am refering to it as a
single character.
-tkc
More information about the Python-list
mailing list