Skip to content
String Methods

format_map()

Fill named replacement fields from one mapping such as a dictionary.

str.format_map(mapping)

Replace named fields such as {name} using values from one dictionary-like mapping.

This is useful when all replacement values are already collected in a dictionary.

Parameters

NameDescription
mappingA dictionary-like object that supplies values for named fields.

Returns

A new formatted string.

Try it

Run it and change it
template = "Hello, {name}!"
values = {"name": "Ada"}
print(template.format_map(values))

Worth knowing

  • format_map() takes one mapping, while format() accepts separate positional and named values.

Related entries