[Edu-sig] Strange results

kirby urner kirby.urner at gmail.com
Tue Jan 3 11:42:36 CET 2012


On Tue, Jan 3, 2012 at 2:23 AM, Andrzej Kapanowski <ufkapano at gmail.com> wrote:
> Hello!
>
> My friend noticed strange results from Python 2.5.2:
>
>>>> b=47
>>>> 0-b/2
> -23
>>>> -b/2+0
> -24
>
> Anybody can explain that?
>

It's integer division:

>>> -1/2
-1
>>> 1/2
0

Not symmetrical.  Why?

http://www.peterbe.com/Integer-division-in-programming-languages

Helps some maybe.

Kirby

> Regards,
> Andrzej Kapanowski
>
>
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/mailman/listinfo/edu-sig
>


More information about the Edu-sig mailing list