Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

str.format_map

Resolves named replacement fields directly against a supplied mapping.

Version: Python 3.14; repository image, production runtime not attested

Syntax

template.format_map(mapping)

Resolves named replacement fields directly against a supplied mapping.

Repeated fields perform repeated lookups in the same mapping; missing ordinary dictionary keys raise KeyError.

Lookup goes directly through the original mapping, without unpacking it into keyword arguments. Here x and y yield 3 and 8. Repeating the x field reads 3 twice. A mapping subclass can implement __missing__ to customize missing-key lookup.

Examples

coords = {"x": 3, "y": 8}
print("{x}/{y}".format_map(coords))
print("{x}/{x}".format_map(coords))

Result

3/8
3/3

Lookup goes directly through the original mapping, without unpacking it into keyword arguments. Here x and y yield 3 and 8. Repeating the x field reads 3 twice. A mapping subclass can implement `__missing__` to customize missing-key lookup.

Sources