考慮以下幾點:這是Python 2.7.1中的一個數字比較中的錯誤嗎?
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 2.0
>>> print x < 2.0
False
>>>
>>> x = 2.2
>>> x -= 0.2
>>> print x < 2.0
False
>>>
>>> x = 2.4
>>> x -= 0.2
>>> x -= 0.2
>>> print x < 2.0
True
>>> print x
2.0
爲什麼二號的最後一條語句打印真正的從2.4到2.0,當x減少?我錯過了什麼?
浮點錯誤熊。 (請參閱[這裏](http://stackoverflow.com/questions/588004/is-javascripts-floating-point-math-broken)瞭解JavaScript的等價物)。 – 2013-03-05 07:37:15
[浮點運算可能不準確](http://docs.python.org/2/tutorial/floatingpoint.html) – Volatility 2013-03-05 07:37:24