[Tutor] (no subject)

Don Arnold darnold02@sprynet.com
Sat, 10 Aug 2002 07:47:05 -0500


----- Original Message -----
From: <alan.gauld@bt.com>
To: <anandrs@hexaware.com>; <tutor@python.org>
Sent: Friday, August 09, 2002 12:11 PM
Subject: RE: [Tutor] (no subject)


> Please use plain text when posting.
>
> > I am having a strange problem with my python code for
> > reversing a number.
>
> Try converting to a string and then iterating over
> the string from back to front using range...
>
>
> > while (number/10) > 1 :
> >   number = number/10
>
> I suspect you are using Python 2.2 which no longer
> does integer division with /.
>
> Try it at the >>> prompt to see how it works
>
> >>> 123/10
> >>> (123/10)%10
>
> etc.
>
> I think the new integer division operator is '//'
>
> I could be wrong, but that's my guess...
>
> Alan G.

Python 2.2 still defaults to integer division unless you import division
from __future__. After that,  // performs integer division and / performs
'regular' division:

>>> 2/3
0
>>> from __future__ import division
>>> 2/3
0.66666666666666663
>>> 2//3
0
>>>

Don