1/2 evaluates to 0

Paul Rudin paul.nospam at rudin.co.uk
Wed Oct 12 06:28:51 EDT 2011


Laurent Claessens <moky.math at gmail.com> writes:

> Hi all
>
>
> This is well known :
>
>>>> 1/2
> 0
>
> This is because the division is an "integer division".
>
> My question is : how can I evaluate 1/2 to 0.5 ? Is there some non
> integer division operator ?
> Up to now I workarounded writing float(1)/2. Is there an other way ?

from __future__ import division

Or use operator.truediv

Or use python 3.






More information about the Python-list mailing list