Pass in the tuple using *arg variable arguments call syntax:
s = "x{}y{}z{}"
tup = (1,2,3)
s.format(*tup)
The *
before tup
tells Python to unpack the tuple into separate arguments, as if you called s.format(tup[0], tup[1], tup[2])
instead.
Or you can index the first positional argument:
s = "x{0[0]}y{0[1]}z{0[2]}"
tup = (1,2,3)
s.format(tup)
Demo:
>>> tup = (1,2,3)
>>> s = "x{}y{}z{}"
>>> s.format(*tup)
'x1y2z3'
>>> s = "x{0[0]}y{0[1]}z{0[2]}"
>>> s.format(tup)
'x1y2z3'