Python String format_map() Method

Last Updated:

Python String format_map()

The format_map() method returns 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.

Example

Python Compiler
a = { 'name': 'John Doe', 'num': 45 } print("{name} lucky number is {num}".format_map(a))

Syntax

txt.format_map(input_dict)

Parameter Values

ValueTypeExplanation
input_dict Required Specifies the variable in which the input dictionary is stored.

Return Value

ValueExplanation
String Returns the formatted string.

More Examples

In the following example, we will use array within object as an input dictionary.

Example

Python Compiler
a = { 'name': ['John Doe', 'Adam'], 'num': [45, 36] } print("{name[0]} lucky number is {num[0]}".format_map(a)) print("{name[1]} lucky number is {num[1]}".format_map(a))

Share this Page

Meet the Author