0

What does {:.{}f} do?

X = 100.1205 Y = str(X)[6] print('{:.{}f}'.format(X,Y) #100

7th May 2019, 11:20 AM
Thimira Rathnayake
Thimira Rathnayake - avatar
2 ответов
+ 5
The outer pair of {} refers to X, the inner pair refers to Y. Y = str(X)[6] = 0, so it's the same as {:.0f} which means "show the number with 0 decimal places"
7th May 2019, 12:03 PM
Anna
Anna - avatar
0
Thanks! Anna
7th May 2019, 12:24 PM
Thimira Rathnayake
Thimira Rathnayake - avatar