wtf

Jean-Paul Calderone exarkun at divmod.com
Thu Apr 26 20:39:31 CEST 2007


On Thu, 26 Apr 2007 21:35:03 +0300, Sergiy <dailylama at gmail.com> wrote:
>print 1 / 2
>print -1 / 2
>
>0
>-1
>
>correct?

  Quoting http://www.python.org/doc/lib/typesnumeric.html:

(1)
    For (plain or long) integer division, the result is an integer.
The result is always rounded towards minus infinity: 1/2 is 0, (-1)/2
is -1, 1/(-2) is -1, and (-1)/(-2) is 0. Note that the result is a long
integer if either operand is a long integer, regardless of the numeric
value.

Jean-Paul



More information about the Python-list mailing list