Python String format_map() Method
Example
Insert the name and age from a dictionary into the placeholders.
myvar = {"name" : "Jane", "age" : 36}
txt = "Happy birthday {name} you are now on level {age}!"
print(txt.format_map(myvar))
Try it Yourself »
Definition and Usage
The format_map()
method formats the specified
values of a dictionary and insert them inside the string's placeholders.
The format_map()
method returns the formatted
string.
Syntax
string.format_map(dictionary)
Parameter Values
Parameter | Description |
---|---|
dictionary | Required. A dictionary. The values in the dictionary can be formatted and used in the string. |