1/2 evaluates to 0

Noah Hall enalicho at gmail.com
Wed Oct 12 06:25:34 EDT 2011


On Wed, Oct 12, 2011 at 11:14 AM, Laurent Claessens <moky.math at gmail.com> wrote:
> 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

Include from __future__ import division on the top of your file

>>> from __future__ import division
>>> 1/2
0.5



More information about the Python-list mailing list