negative numbers are not equal...

castironpi castironpi at gmail.com
Fri Aug 15 05:44:32 CEST 2008


On Aug 14, 4:31 pm, Wojtek Walczak <gmin... at bzt.bzt> wrote:
> On Thu, 14 Aug 2008 18:23:21 -0300, ariel ledesma wrote:
> > i see now, so i guess that's also why id() returns the same address for
> > them as well...
>
> It just have to work like this.
>
> a is b
>
> is actually equal to:
>
> id(a) == id(b)
>
> so there is no other way for id() in such case.
>
> Hope this helps.
>
> --
> Regards,
> Wojtek Walczak,http://www.stud.umk.pl/~wojtekwa/

For

a= 6
b= a

the test

a is b

should clearly return true.  Python distinguishes what mathematics
does not, between identity and equality.  Clearly 5+4 and 6+3 -
evaluate- to the same, but math doesn't define whether they are the
same, and in some sense the question isn't asked ordinarily, or isn't
debated.  I want to infer that math doesn't define the 'is' relation
as Python knows it.

I feel the documentation should state, 'the interpreter is free to
return a -new- equivalent non-identical object in the case of
immutables.'

My tests:

>>> a= -6
>>> a is -6
False
>>> -6 is -6
True

I don't know a convincing argument for the truth of Is( -6, -6 ).
Perhaps you could make one, or one for the permissibility of Is( a,
b ) & ~Equal( a, b )... identical non-equivalent.



More information about the Python-list mailing list