+ 2

print(format (float(5)/float(3), '.3' )) there output comes 1.67 if i am use , '.3f' then output comes 1.667.

so what is the roll of "f" in this tell me plz ?????

5th Aug 2021, 5:31 PM
VɪsʜᴀL
VɪsʜᴀL - avatar
2 Réponses
+ 5
VɪsʜᴀL , 'f' is a format specifier for float numbers, '3' means that the output shows 3 digits from decimal places. to get more familiar with output formating, you can read this tutorial: https://realpython.com/JUMP_LINK__&&__python__&&__JUMP_LINK-f-strings/
5th Aug 2021, 5:46 PM
Lothar
Lothar - avatar
+ 1
When dealing with floats The format ".3" means: there shell be displayed 3 digits at most The format ".3f" means: the number is to be shown in fixed point notation with a precision of 3 digits after the point P. S.: learn f-strings, they're much easier to read
6th Aug 2021, 12:25 PM
Angelo
Angelo - avatar