Python String | format_map()
format_map() function is an inbuilt function in Python, which is used to return an dictionary key’s value.
Syntax :
string.format_map(z)
Here z is a variable in which input dictionary is stored and string is the key of the input dictionary.
Parameters :
input_dict : Takes a single parameter which is input dictionary.
Returns :
Returns key's values of the input dictionary.
Code #1 :
# input stored in variable a. a = {'x':'John', 'y':'Wick'} # Use of format_map() function print("{x}'s last name is {y}".format_map(a)) |
Output:
John's last name is Wick
Code #2 :
# input stored in variable a. a = {'x':"geeksforgeeks", 'y':'b'} # Use of format_map() function print('{x} {y}'.format_map(a)) |
Output :
geeksforgeeks b
Code #3 :
# Input dictionary profession = { 'name':['Barry', 'Bruce'], 'profession':['Engineer', 'Doctor'], 'age':[30, 31] } # Use of format_map() function print('{name[0]} is an {profession[0]} and he' ' is {age[0]} years old.'.format_map(profession)) print('{name[1]} is an {profession[1]} and he' ' is {age[1]} years old.'.format_map(profession)) |
Output :
Barry is an Engineer and he is 30 years old. Bruce is an Doctor and he is 31 years old.
Application :
The format_map() function can be used in many practical application.
# Python code showing practical # use of format_map() function def chk_msg(n): # input stored in variable a. a = {'name':"George", 'mesg':n} # use of format_map() function print('{name} has {mesg} new messages'.format_map(a)) chk_msg(10) |
Output :
George has 10 new messages
Recommended Posts:
- Python | Check if given string can be formed by concatenating string elements of list
- String slicing in Python to check if a string can become empty by recursive deletion
- Python | Merge Tuple String List values to String
- Python | Sorting string using order defined by another string
- Python | Check if string ends with any string in given list
- String slicing in Python to rotate a string
- Python | Check if a given string is binary string or not
- Python | Sort each String in String list
- Python String
- Python String | min()
- Python | Add one string to another
- Python String | max()
- Python String | find()
- Python string | ascii_lowercase
- Python string | ascii_uppercase
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

