re OnInteger division
Chris Barker
chrishbarker at home.net
Wed Nov 7 16:02:31 EST 2001
Fredrik Lundh wrote:
> > so:
> > 9/4 = 2
> > 9 %4 = 1
> >
> > and
> > (9/ 4) *4 + (9%4) = 9
>
> on the other hand,
>
> >>> from __future__ import division
> >>> (9/4)*4 + (9%4)
> 10.0
>
> oh well.
Ah, but
>>> (9./ 4) *4 + (9%4) # without future division
10.0
and:
>>> (9//4)*4 + (9%4) # with future division
should work fine, as should:
>>> (9/4)*4
With either floats or integers, which is a whole lot more clear.
-Chris
--
Christopher Barker,
Ph.D.
ChrisHBarker at home.net --- --- ---
http://members.home.net/barkerlohmann ---@@ -----@@ -----@@
------@@@ ------@@@ ------@@@
Oil Spill Modeling ------ @ ------ @ ------ @
Water Resources Engineering ------- --------- --------
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------
More information about the Python-list
mailing list