decimal numbers

Chris Angelico rosuav at gmail.com
Sat Feb 15 11:13:20 CET 2014


On Sat, Feb 15, 2014 at 9:04 PM, Frank Millman <frank at chagford.com> wrote:
> If you are using python2, an integer divided by an integer always returns an
> integer -
>
>>>> 10/3
> 3
>
> It was changed in python3 to return a float -
>
>>>> 10/3
> 3.3333333333333335
>
> You can reproduce the python3 behaviour in python2 by adding a 'future'
> directive -
>
>>>> from __future__ import division
>>>> 10/3
> 3.3333333333333335
>

Conversely, you can get an integer result by using floor division:

>>> 10//3
3

ChrisA



More information about the Python-list mailing list