PEP-xxx: Unification of for statement and list-comp syntax

Tim Roberts timr at probo.com
Wed May 24 06:12:33 CEST 2006


Edward Elliott <nobody at 127.0.0.1> wrote:

>bruno at modulix wrote:
>
>> Edward Elliott wrote:
>>> You mean like this:
>>> 
>>> s = "foo" + "bar"
>>> s = 'foo' + 'bar'
>>> s = 'foo' 'bar'
>>> s = '%s%s' % ('foo', 'bar')
>[snip]
>> The real mantra is actually :
>> "There should be one-- and preferably only one --obvious way to do it"
>> 
>> Please note the "should", "preferably", and "obvious".
>
>Touche.  Please tell me which of the above should obviously be the
>preferable way to concatenate strings.  All those weasel words prove my
>point: it's a vague and watered-down guideline that gives way in the face
>of other considerations.

Well, there's really no difference between the first two, and this would
work just as well:

   s = """foo""" + '''bar'''

The third line only works for string constants, not for string variables.
IMHO, it would be the preferred method for concatenating string constants.

At one time, it was said that the "%" operator was the fastest way to
concatenate strings, because it was implemented in C, whereas the +
operator was interpreted.  However, as I recall, the difference was hardly
measurable, and may not even exist any longer.
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list