0
Explain plzzx
x = 12.3456789 print('the value of x is %3.2f'%x)
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}')
+ 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
0
RKK but itâs output is 12.35
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.