Home >>Python String Methods >Python String format_map() method
Python string format_map() method is employed to return a dictionary key’s value. It is almost like the format() method but the difference is that the format() method creates a new dictionary whereas the format_map() doesn't.
Syntax:string.format_map(input_dict)
Parameter | Description |
---|---|
input_dict | It defines the variable in which the input dictionary is stored. |
a = {'x':'Jerry', 'y':'Stark'}
print("{x}'s last name is {y}".format_map(a))
# Input dictionary
profession = { 'name':['Barry', 'Bruce'],
'profession':['Flash', 'Batman'] }
# Use of format_map() function
print('{name[0]} is the {profession[0]}. '
.format_map(profession))
print('{name[1]} is the {profession[1]}. '
.format_map(profession))