semi-concatenated strings

Grant Griffin Grant_member at newsguy.com
Fri May 31 14:26:00 EDT 2002


In article <mailman.1022863315.9955.python-list at python.org>, Rich says...
>
...
>Here's why I personally like this:
>
>>>>> '%s' 'x' % (5)
>'5x'

>>>> '%s' + 'x' % (5)
>Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
>TypeError: not all arguments converted

So it looks like the implicit "+" operator has a higher precedence than the
explicit "+" operator.  (BTW, who knew that a language that doesn't have "++"
would need two string concatenation operators?)

Perhaps that was just an example, but what was so bad about?:

>>> '%sx' % (5,)    # don't hesitate to add trailing "," here <wink>
'5x'

or even?:

>>> ('%s' + 'x') % (5,)
'5x'

the-only-thing-worse-than-using-explicit-operators-is
   -explicitly-specifying-their-order-<wink>-ly y'rs,

=g2

_________________________________________________________________________

Grant R. Griffin                                           g2 at dspguru.com
Publisher of dspGuru                               http://www.dspguru.com
Iowegian International Corporation                http://www.iowegian.com




More information about the Python-list mailing list