.format_map()

hP3188941580's avatar
Published Oct 19, 2023
Contribute to Docs

The .format_map() string method takes a single parameter which is the input dictionary and returns the key’s values.

Syntax

string.format_map(d)

d is the dictionary to be addressed.

Example

The example below uses .format_map() to return the values stored in x and y:

# Input stored in variable a.
a = {'x':'Mike', 'y':'Perry'}
# Use of format_map() function
print("That DJ is {x} {y}".format_map(a))

The output will look like this:

That DJ is Mike Perry

Codebyte Example

The following code is runnable and demonstrates the use of .format_map():

Code
Output
Loading...

All contributors

Contribute to Docs

Learn Python on Codecademy