Python 3000 deat !? Is true division ever coming ?

Rocco Moretti roccomoretti at hotpop.com
Tue Feb 14 11:53:14 EST 2006


Gregory Piñero wrote:
> On 14 Feb 2006 06:44:02 -0800, rainbow.cougar at gmail.com
> 
> 
>>5./2.=2.5 is floating point math, with all the round off errors that
>>incorporates.
> 
> Thanks Curtis, I never knew that trick.  I guess for variables do have
> true division you have to make them floats?  e.g.
> float(var1)/float(var2)?  Or do you know a less typing approach for
> that?

Google "python true division" -> I'm feeling lucky:

http://www.python.org/doc/2.2.3/whatsnew/node7.html

 From the web page:

"""
* By including a from __future__ import division in a module(*), the / 
operator will be changed to return the result of true division, so 1/2 
is 0.5. Without the __future__ statement, / still means classic 
division. The default meaning of / will not change until Python 3.0.
"""

*As the first non-docstring/non-comment line.

Note that that's for a module -- the interactive interpreter won't 
respond the same way to the "from __future__ import" statement.



More information about the Python-list mailing list