off topic but please forgive me me and answer

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Apr 2 04:38:04 CEST 2010


On Thu, 01 Apr 2010 19:55:27 -0400, David Robinow wrote:

>>> superpollo wrote:
>>> > how much is one half times one half?
[...]
>  Well, my python says:
> 
> $ python -c "print 1/2 * 1/2"
> 0
> 
>  But that's not what I learned in grade school.
> (Maybe I should upgrade to 3.1?)

Python 2.x defaults to integer division, a design error which has been 
rectified in 3.x.

One can do any of these:

[steve at sylar ~]$ python3.1 -c "print(1/2 * 1/2)"
0.25
[steve at sylar ~]$ python2.6 -c "from __future__ import division; print 1/2 
* 1/2"
0.25
[steve at sylar ~]$ python2.6 -Q new -c "print 1/2 * 1/2"
0.25
[steve at sylar ~]$ python2.6 -c "print 0.5 * 0.5"
0.25


and probably many others as well.



-- 
Steven



More information about the Python-list mailing list