On Apr 26, 8:34 pm, asker <[EMAIL PROTECTED]> wrote:
> Hello:
> I have next Python 2.5.1 instructions:
>
> >>> a=12.34
> >>> b=11.23
> >>> print a+b
>
> 23.57
>
> >>> print "%15.2f" % (a+b)
>
>           23.57
>
> But:>>> print "%15.2f" % a+b
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: cannot concatenate 'str' and 'float' objects
>
> Is this correct for Python to issue this error?

The % operator has higher precedence than +.  Thus, "%15.2f" % a+b ==
("%15.2f" % a)+b, an illegal str+float addition.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to