sameness/identity
Xavier Defrang
xavier at perceval.net
Mon Oct 1 06:22:52 EDT 2001
On Mon, 1 Oct 2001, Markus Schaber wrote:
> Just to confuse you some more:
>
> >>> a = 3
> >>> b = 3
> >>> a is b
> 1
> >>> a = 10000
> >>> b = 10000
> >>> a is b
> 0
Damn, this is weird. :)
After reading that, I wrote a small script :
<snip>
a = 0
b = 0
while a is b:
a += 1
b += 1
print id(a), a
print id(b), b
</snip>
Here's the output with Python 2.1:
<snip>
136907204 100
136907168 100
</snip>
That '100' definetly looks like some hardcoded limit, has anybody a clear
explanation for this? Why the interpreter behaves differently for numbers
lower than 100 and the others? I guess it's for optimization purpose
since most algorithms deal with small numerical values but I'd be really
happy if I knew what's really going on in here...
Regards,
Xavier Defrang
Perceval R&D Team
xavier at perceval.net
-------------------------------------------------
Perceval Technologies SA/NV Tel: +32-2-6409194
Rue Tenbosch, 9 Fax: +32-2-6403154
B-1000 Brussels http://www.perceval.net
BELGIUM info at perceval.net
-------------------------------------------------
More information about the Python-list
mailing list