Skip to content
Advertisement

How can I do a dictionary format with f-string in Python 3 .6?

How can I do this format with a Python 3.6 F-String?

person = {'name': 'Jenne', 'age': 23}

print('My name {0[name]} and my age {1[age]}'.format(person, person))
print('My name {0} and my age {1}'.format(person['name'], person['age']))

Advertisement

Answer

Well, a quote for the dictionary key is needed.

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

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement