0

Explain plzzx

x = 12.3456789 print('the value of x is %3.2f'%x)

8th Jun 2020, 3:04 PM
Siddhant Saxena
Siddhant Saxena - avatar
5 Answers
+ 7
You can also use this for getting the same result. It is more pythonic and it's called format- string: print(f'the value of x is {x:.2f}')
8th Jun 2020, 3:37 PM
Lothar
Lothar - avatar
+ 2
“%” operator is used to format as well as set precision in python.(like printf in C) so in your case, we are setting the Decimal precision to 2 (since ". 2") therefore the output is 12.34 Read this for depth... https://www.python-course.eu/python3_formatted_output.php
8th Jun 2020, 3:15 PM
minirkk
minirkk - avatar
0
RKK but it’s output is 12.35
8th Jun 2020, 4:35 PM
Siddhant Saxena
Siddhant Saxena - avatar
0
Lothar RKK you can check it’s output
8th Jun 2020, 4:38 PM
Siddhant Saxena
Siddhant Saxena - avatar
0
x = 12.3456789 print('the value of x is %3.2f'%x)..... ...the ".2f" in the format specifier is the number of decimal places to display. ...the "3" in format specifier is the minimum field width....try changing it to something like 10 to see how it impacts the output.
8th Jun 2020, 5:26 PM
rodwynnejones
rodwynnejones - avatar