There should be one-- and preferably only one --obvious way to do it.
This would be the 4th way of formatting strings in Python. There should be one-- and preferably only one --obvious way to do it.
This would be the 4th way of formatting strings in Python.I don't think it would. If I understand this PEP correctly, the "format" method is significantly more dynamic. For instance, I don't think this new PEP would allow for cases where the template isn't stored directly in the program, or where the values to interpolate are not local variables. So you would still need to keep str.format around for those use cases.
'{x} blah blah blah {y}'.format(x=x, y=y)
is more readable than '%s blah blah blah %s' % (x, y)
even if the former is a bit longer.On top of that, there's a whole bunch of stuff you can do with .format() that just isn't possible with %.
'%s blah blah blah %s' % (x, y)
'{x} blah blah blah {y}'.format(x=x, y=y)
'%(x)s blah blah blah %(y)s'%{'y':y, 'x':x} Although practicality beats purity.*obligatory "not really, but in most cases" disclaimer