print - bug or feature - concatenated format strings in a print statement
Matt Nordhoff
mnordhoff at mattnordhoff.com
Wed Mar 18 01:19:42 EDT 2009
bdb112 wrote:
> Thanks for all the replies:
> I think I see now - % is a binary operator whose precedence rules are
> shared with the modulo operator regardless of the nature of its
> arguments, for language consistency.
> I understand the arguments behind the format method, but hope that the
> slightly idiosyncratic print( ..% ..) remains, as the vaguely
> pictorial "printf" format string is clearer for a long line with
> several arguments.
> I will use the "implicit string concatenation" to solve my problem but
> it is a little odd that an "invisible" operator is stronger than a
> visible one. (+).
The implicit string concatenation is actually done by the compiler; it
isn't an operator at all. Look:
>>> import dis
>>> def f():
... return "foo" "bar"
...
>>> dis.dis(f)
2 0 LOAD_CONST 1 ('foobar')
3 RETURN_VALUE
--
More information about the Python-list
mailing list