.format_map()

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():

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn Python on Codecademy