Difference between 'is' and '=='
reply.in.the.newsgroup at my.address.is.invalid
Tue Mar 28 00:59:37 CEST 2006
>The Python specification allows but does not require such behind-the-scenes
>implementation optimization hacks. As released, CPython 2.4 caches -5 to
>99, I believe. In 2.5, the upper limit was increased to 256. The limits
>are in a pair of #define statements in the int object source file. Anyone
>who compiles from source can adjust as desired (though the corresponding
>test will fail unless also adjusted ;-).
>I think the visibility of this implementation detail from Python code is an
>example of a leaky abstraction. For more, see
Joel has his abstractions wrong. TCP doesn't guarantee reliable delivery,
unlike IP it delivers reliably or it tells you it cannot. SQL perormance
doesn't break abstraction, since performance isn't part of SQL. You _can_
drive as fast when it's raining.
Now, about identity and equality. As you know, identity implies equality,
but equality doesn't imply identity. You seem to assume that when identity
is not implied, it should be undetectable. But why?
Here's A, there's B, they may or may not be identical, they may or may not
What are you suggesting?
1. If A and B are of comparable types, and A equals B, we should not be
allowed to evaluate "A is B".
2. If A and B are of comparable types, and A equals B, A should be B.
3. If A and B are of comparable types, and A equals B, A should not be B.
4. If A and B are of comparable types, and A equals B, "A is B" should not
evaluate to a boolean value.
5. When A and B are of comparable types, we should not be allowed to
evaluate "A == B" :-)
More information about the Python-list