doesNotUnderstand ?

Hans Nowak wurmy at earthlink.net
Thu Nov 29 12:12:24 EST 2001


Gerardo Richarte wrote:
> 
> > `__getattr__` is your friend.
> 
>     thanks everybody...
> 
> >>> -1/1000000000000000000000000000000000000000000000L
> -1L
> 
>     add as many zeros as you whis...
> 
> I can undersrtand -1 >> 1000 = -1, but not -1/10000000L ...

It's Python's integer division at work...

>>> -1/100000L
-1L
>>> 1/100000L
0L
>>> -(1/100000L)
0L

Integer division rounds down to the nearest integer. For positive
numbers, this is unsurprising:

>>> 9/4
2

(2.25 -> 2), but negative numbers may not yield what you expected:

>>> -9/4
-3

-2.25 -> -3, because -3 is the first integer *lower* than -2.25.

I must admit, it does look strange to see things like -1/10 and
get -1 back.

--Hans



More information about the Python-list mailing list