Coding Style: Quotes

Thorsten Kampe thorsten at thorstenkampe.de
Sat Sep 14 10:28:30 CEST 2002


* Michael Stenner
> On Fri, Sep 13, 2002 at 10:05:45PM +0200, Thorsten Kampe wrote:
>> * John Waycott
>>> I'm curious if others have adopted any standards for choice of single vs.
>>> double quotation marks to delimit strings. A look through the standard
>>> library reveals the choice of one over the other is rather arbitrary. I
>>> suspect it really makes no difference, but the question has come up during a
>>> code review.
>> 
>> Python itself seems to "prefer" single quotes slightly:
>> 1: >>> "String"
>> 1:     'String'
>> 2: >>>
>
> Just because it uses the single quote doesn't mean it prefers it.  It
> (or the authors, rather) had to choose.  They couldn't just not pick
> one.  Also, the method you use to input the string IS NOT part of the
> string, and so should be dropped after it's role (encoding the string)
> is complete.  Therefore, your example does not support your statement.
>
> Of course, I suspect it is for just this reason that you quoted
> "prefer". :)

The Python interpreter has it's own preferences of outputting/printing 
objects. So the question "'" versus """ is just a part of a wider 
discussion. I asked myself the same question when I started four weeks 
ago. How to put spaces, commas, string delimiter, indent etc.?

Instead of doing it my way, I decided to do it the Python way for sake 
of readability of my code.

1: >>> 1
1:     1
2: >>> { }
2:     {}
3: >>> [ 1 , 2 ]
3:     [1, 2]


Thorsten



More information about the Python-list mailing list