Fun with numbers - dammit, but I want a cast!

Hannu Kankaanpää hanzspam at yahoo.com.au
Mon Aug 11 16:36:04 EDT 2003


Andrew Koenig <ark at acm.org> wrote in message news:<yu99fzk8715z.fsf at tinker.research.att.com>...
>         2) At the beginning of your source file, execute:
> 
>                 from __future__ import division
> 
>           Python is going to change its behavior so that division always
>           returns a floating-point value.  This statement causes that new
>           behavior to occur now.

By the way, do you know a reason why after doing

from __future__ import division

this still happens:

>>> 3.0 // 2
1.0

Wouldn't it be more convenient to present the resulting whole
number as an integer now, since division operation on integers
works correctly? At least IMO the operation

>>> 3.0 // 2
1

would be more convenient and natural, and floor division could then be
used to get array indices for example:

print arr[position // scale]

Not that I -really- care either way, since casting division result
to int isn't verbose either. Just curious, if you or anyone
knows the reason for new floor div working this way.




More information about the Python-list mailing list