我是一個python newbie.I剛熟悉格式化方法。format():ValueError:不允許在整數格式說明符中使用精度
從一本書,我讀學習Python
What Python does in the format method is that it substitutes each argument
value into the place of the specification. There can be more detailed specifications
such as:
decimal (.) precision of 3 for float '0.333'
>>> '{0:.3}'.format(1/3)
fill with underscores (_) with the text centered
(^) to 11 width '___hello___'
>>> '{0:_^11}'.format('hello')
keyword-based 'Swaroop wrote A Byte of Python'
>>> '{name} wrote {book}'.format(name='Swaroop', book='A Byte of Python')
在Python解釋器,如果我嘗試
print('{0:.3}'.format(1/3))
它給人的錯誤
File "", line 24, in
ValueError: Precision not allowed in integer format specifier
與
from __future__ import division
語句複製這個是什麼「{0:0.3}是什麼意思?格式如何替代這些值? – liv2hak