NEWB: dividing numbers
MRAB
google at mrabarnett.plus.com
Sun Mar 8 19:26:36 EDT 2009
Lo wrote:
> I just tried python first time.
>
> 2/3
>
> the result is zero
>
> I want the result to be .333...
>
> How do I get this?
>
That's integer division (integer divided by integer is integer).
If you want the result to be floating point then make one of them
floating point:
2.0 / 3
or do this first:
from __future__ import division
In the future and in Python 3.x "/" will always return floating point.
For an integer result use "//" instead.
BTW, 2.0/3.0 still isn't 0.333... ;-)
More information about the Python-list
mailing list