String formatting | Sololearn: Learn to code for FREE!


String formatting

Why couldn't i format my name n age ??

7/1/2020 6:40:45 AM


5 Answers

New Answer


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


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')}")


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


Didn't work


you put ,format and not .format