0
Why in the first case outputs 3 numbers after ".", And in the second 2 numbers after "."
1;print('{0:.3}'.format(1/3)) , outputs 0.333 2:print('{0:.3}'.format(5/3)) , outputs 1.67
5 Antworten
+ 2
Scroll up (not down) a bit and read the "None" part (and the "g" part).
https://docs.python.org/3.7/library/string.html#format-examples
+ 2
if you use additional “f” it will work for both format versions:
print('{0:.3f}'.format(1/3))
print('{0:.3f}'.format(5/3))
print(f'{1/3:.3f}')
print(f'{5/3:.3f}')
# output:
0.333
1.667
0.333
1.667
+ 1
Not sure, but if you use the format specifier correctly it will work: {0:.3f}
0
I’m wondering why it’s exactly 2 digits after the dot, because as I understand it, 0.3 means that the result will be displayed with an accuracy of 3 digits, but in the second case only two digits will be displayed, why?
0
Thank you all!