Python String format_map() MethodPython Functions

Difficulty Level:
Difficulty Level:

The format_map() method generates a formatted version of the string based on the mapping dictionary provided.

Note: The format_map() method is similar to str.format(). The difference is that str.format() creates a new dictionary whereas str.format_map() doesn’t.

Example

point = {'x':14, 'y':25}
print('{x} {y}'.format_map(point))

point = {'x':1, 'y':1, 'z': 1}
print('{x} {y} {z}'.format_map(point))

Output:

14 25
1 1 1

Syntax

str.format_map(mapping)

Parameters

The method takes a single parameter which is an input dictionary used for mapping.

Return Value

Returns a formatted version of the string based on mapping dictionary.

Advertisement

© 2021 Pythonexample.org, all rights reserved. Privacy Policy | Contact Us