String formatting | Sololearn: Learn to code for FREE!

0

String formatting

Why couldn't i format my name n age ?? https://code.sololearn.com/cSzP3eQ4VKS2/?ref=app

7/1/2020 6:40:45 AM

Mani

5 Answers

New Answer

+5

sentence = 'my name is {0} N my age is {1}'.format(student['name'],student['age'])

+4

From my point of view it's better to use f-string: student = {'name': 'amni', 'age': 10} sentence = f"my name is {student.get('name')} my age is {student.get('age')}" print(sentence) # or direct with print() print(f"my name is {student.get('name')} my age is {student.get('age')}")

+1

You just have to change the comma in your code to a dot: .format(student['name'],student['age'])

0

Didn't work

0

you put ,format and not .format