Python String format_map() Method

The format_map formats a string by taking a dictionary of key-value pairs that define the placeholder names and their values, and replacing the placeholders in a string with the values.

Syntax

Python
string.format(map)

Parameters

ParameterDescription
map Required. The map containing the placeholder names (the keys) and the values that will replace them in the string.

Example

Python
map  = { 'salePrice': 49, 'discount': 5 }
text = "Sale price: ${salePrice}. That's a {discount}% discount"
print(text.format_map(map))

Output

Sale price: $49. That's a 5% discount.