Format Strings -- Real vs. Expected Behaviour

Tim Peters tim.one at home.com
Mon Apr 16 21:12:08 EDT 2001


[Brad Bollenbach]
> ...
> whereas this:
>
>     print "%s " + \
>     "%s" % ("hello", "world")
>
> Results in "TypeError: not all arguments converted".
>
> but this:
>
>     print ("%s " + \
>     "%s") % ("hello", "world")
>
> prints "hello world" as well.
> ...

Note that % has higher precedence than +:  those parentheses in the second
example are doing more than you think they're doing!





More information about the Python-list mailing list