There are three options:
>>> 4 / float(100) 0.04 >>> 4 / 100.0 0.04
which is the same behavior as C, C ++, Java, etc., or
>>> from __future__ import division >>> 4 / 100 0.04
You can also activate this behavior by passing the -Qnew argument to the -Qnew interpreter:
$ python -Qnew >>> 4 / 100 0.04
The second option will be the default in Python 3.0. If you want to have the old integer division, you need to use the // operator.
Edit : Added section about -Qnew , thanks to ΤΖΩΤΖΙΟΥ !
Torsten Marek Sep 22 '08 at 20:08 2008-09-22 20:08
source share