我正在閱讀wrox Beginning Python一書。在第2章中,示例狀態爲在python中顯示小數範圍內
>>> print "$.03f" & 30.0
$30.001
但是,這並不能解釋命令的行爲。當.3和.003等在shell中具有相同的行爲時,爲什麼要使用.03?此外,它不能解釋時,我只是用3
>>> print "%.03f" % (2.34567891)
2.346
>>> print "%.003f" % (2.34567891)
2.346
>>> print "%.0003f" % (2.34567891)
2.346
>>> print "%.3f" % (2.34567891)
2.346
>>> print "%3f" % (2.34567891)
2.345679
我試圖尋找,但不可能得到的結果,因爲我不知道相關的關鍵字是什麼什麼happends。
的''%經營者被淘汰,慢慢來。我開始使用'format':'print'{:.4}'。format(2.34567891)'。 – Blender