Python String format_map() Method

You are Here:

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

Output

xxxxxx

Syntax

txt.format_map(input_dict)

Parameter Values

ValueTypeExplanation
input_dictRequiredSpecifies the variable in which the input dictionary is stored.

Return Value

ValueExplanation
StringReturns 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))

Output

John Doe lucky number is 45 Adam lucky number is 36

Reminder

Hi Developers, we almost covered 90% of String functions and Interview Question on Python with examples for quick and easy learning.

We are working to cover every Single Concept in Python.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author