0

String formatting

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

1st Jul 2020, 6:40 AM
Mani
Mani - avatar
5 RĂ©ponses
+ 5
sentence = 'my name is {0} N my age is {1}'.format(student['name'],student['age'])
1st Jul 2020, 6:44 AM
Abhay
Abhay - avatar
+ 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')}")
1st Jul 2020, 2:38 PM
Lothar
Lothar - avatar
+ 1
You just have to change the comma in your code to a dot: .format(student['name'],student['age'])
1st Jul 2020, 7:01 AM
đŸŒ±Zuhal🐛🌿
đŸŒ±Zuhal🐛🌿 - avatar
0
Didn't work
1st Jul 2020, 6:56 AM
Mani
Mani - avatar
0
you put ,format and not .format
2nd Jul 2020, 12:11 PM
Pr0C0d3r
Pr0C0d3r - avatar