[Python-ideas] Briefer string format

Chris Angelico rosuav at gmail.com
Fri Jul 24 04:16:46 CEST 2015

On Fri, Jul 24, 2015 at 11:57 AM, Bruce Leban <bruce at leban.us> wrote:
> You talk about which happens "first" so let's recast this as an operator
> precedence question. Think of f as a unary operator. Does f bind tighter
> than implicit concatenation? Well, all other string operators like this bind
> more tightly than concatenation.
> f'{spam}' '{eggs}'

Thing is, though, it isn't an operator, any more than list display is
an operator. Operators take values and result in values. You can break
out some part of an expression and it'll have the same result (apart
from short-circuit evaluation). With f"...", it's a piece of special
syntax, not something you apply to a string. You can't do this:

fmt = "Hello, {place}!"
place = "world"
print(f fmt)

If f were an operator, with precedence, then this would work. But it
doesn't, for the same reason that this doesn't work:

path = "C:\users\nobody"
fixed_path = r path

These are pieces of syntax, and syntax is at a level prior to all
considerations of operator precedence.


More information about the Python-ideas mailing list