Named placeholders

suggest change

Format strings may contain named placeholders that are interpolated using keyword arguments to format.

Using a dictionary (Python 3.2+)

>>> data = {'first': 'Hodor', 'last': 'Hodor!'}
>>> '{first} {last}'.format_map(data)
'Hodor Hodor!'

str.format_map allows you to use a mapping without unpacking it first. Lookups go through that mapping, so it does not have to be a dict.

Without a dictionary:

>>> '{first} {last}'.format(first='Hodor', last='Hodor!')
'Hodor Hodor!'

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents