On Tue, 19 May 2020 13:36:54 -0500 Tim Chase <python.l...@tim.thechases.com> wrote:
> 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 > > I am influenced by Perl which I used before. In Perl I used double quoted strings when I wanted interpolation. Otherwise single quoted strings. In Rust (or C) it is double quotes for strings and single quotes for characters. You may be right. Consistency is a good thing. So, I have to decide for what I use and be consistent thereafter. -- Manfred -- https://mail.python.org/mailman/listinfo/python-list