semi-concatenated strings
Skip Montanaro
skip at pobox.com
Fri May 31 15:50:26 EDT 2002
'%s' 'x' % (5)
vs.
'%s' + 'x' % (5)
Grant> So it looks like the implicit "+" operator has a higher
Grant> precedence than the explicit "+" operator.
Minor semantic point here. Since the string concatenation is performed by
the compiler, not at runtime, it's probably not correct to call the first
form an implicit "+" operator. Nothing happens at runtime to squash the two
strings together. If you inspect the code object you can see this:
>>> def f():
... '%s' 'x' % (5,)
...
>>> f.func_code.co_consts
(None, '%sx', 5)
Skip
More information about the Python-list
mailing list