In Python, it is tedious to write:
print \"foo is\" + bar + \'.\'
Can I do something like this in Python?
print \"foo is #{ba
I have learned the following technique from Python Essential Reference:
>>> bar = "baz"
>>> print "foo is {bar}.".format(**vars())
foo is baz.
This is quite useful when we want to refer to many variables in the formatting string:
"{x}{y}".format(x=x, y=y) and "%(x)%(y)" % {"x": x, "y": y})."{}{}".format(x, y), "{0}{1}".format(x, y) and "%s%s" % (x, y)).