The format method is more flexible than the chapter explains. This interactive python session illustrates some of the flexibility in the string template pattern and arguments to format.

1
2
3
4
5
6
>>> "{} hi".format(7)
'7 hi'
>>> "{} hi {} there".format(7,8)
'7 hi 8 there'
>>> "{a} hi {b}".format(a=100,b="there")
'100 hi there'

The example shows that it is not even necessary to use a specific number, like "{0}" in the template: if no number is given, then format will take the value from the arguments provided (7 and 8 above). The example also has a different way to refer to arguments, by name (as in keyword arguments). Technically, the format method is treating the keyword arguments as a dictionary, so that "{a}" refers to the value associated with key "a" in the argument dictionary. (The example doesn't show it, but there's also a way to pass an existing dictionary as the argument to format.)