from math import pi
format = 'pi with three decimals: .%3f'
print (format % pi)
pi with three decimals: .3.141593
今天学习的时候因为输错了,导致出现了自己无法理解的结果。为什么是.3.141593呢?
format = 'pi with three decimals: % 3.f'
print (format % pi)
pi with three decimals: 3
这是另一个错误。
format = 'pi with three decimals: % .3f'
print (format % pi)
pi with three decimals: 3.142
这是书中正确的例句。
'%.3f' % pi
'3.142'
取pi的三位小数