close

how to do a dictionary format with f-string in python 3.6?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about how to do a dictionary format with f-string in python 3.6 in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

how to do a dictionary format with f-string in python 3.6?

  1. how to do a dictionary format with f-string in python 3.6?

    Depending on the number of contributions your dictionary makes to a given string you might consider using .format(**dict) instead to make it more readable, even though it doesn't have the terse elegance of an f string.

  2. dictionary format with f-string in python 3.6

    Depending on the number of contributions your dictionary makes to a given string you might consider using .format(**dict) instead to make it more readable, even though it doesn't have the terse elegance of an f string.

Method 1

Well, a quote for the dictionary key is needed.

f'My name {person["name"]} and my age {person["age"]}'

Method 2

Depending on the number of contributions your dictionary makes to a given string you might consider using .format(**dict) instead to make it more readable, even though it doesn’t have the terse elegance of an f string.

>>> person = {'name': 'Jenne', 'age': 23}
>>> print('My name is {name} and my age is {age}.'.format(**person))

My name is Jenne and my age is 23.

Whilst this option is situational, you might like avoiding a snarl up of quotes and double quotes

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read