.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() functionprint("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()
:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Skill path
Analyze Data with Python
Learn to analyze and visualize data using Python and statistics.Includes 8 CoursesWith CertificateIntermediate13 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours