[Tutor] floats acting like integers???

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Tue Jul 27 02:38:49 CEST 2004



On Mon, 26 Jul 2004, Hee-Seng Kye wrote:

> Hi.  To get floats for divisions, either the number you are dividing or
> being divided should be a floating point.
>
>  >>> a = 1.0 / 7		# or a = 1 / 7.0
>  >>> a
> 0.14285714285714285
>  >>> print a
> 0.142857142857


Hi Jeff,


Just as a side note: this does come up often enough as an issue that
there's a long-term plan to change the division operator:

    http://www.python.org/peps/pep-0238.html

The default is still the old behavior (int divided by int -> int).  But
it's possible to enable 'True Division' mode by putting:

###
from __future__ import division
###

at the very top of your program.


Good luck to you!



More information about the Tutor mailing list