472,347 Members | 2,400 Online

# Re: Python "is" behavior

On Fri, 20 Jun 2008 09:31:57 -0700 (PDT), mi*************@gmail.com wrote:
>I am not certain why this is the case, but...
>>>a = 256
b = 256
a is b
True
>>>a = 257
b = 257
a is b
False

Can anyone explain this further? Why does it happen? 8-bit integer
differences?
http://mail.python.org/pipermail/pyt...er/113994.html

Jean-Paul
Jun 27 '08 #1
3 1304
On Jun 20, 9:38*am, Jean-Paul Calderone <exar...@divmod.comwrote:
On Fri, 20 Jun 2008 09:31:57 -0700 (PDT), michalis.avr...@gmail.com wrote:
I am not certain why this is the case, but...
>>a = 256
b = 256
a is b
True
>>a = 257
b = 257
a is b
False
Can anyone explain this further? Why does it happen? 8-bit integer
differences?

http://mail.python.org/pipermail/pyt...er/113994.html

Jean-Paul
Thank you for this Jean-Paul. I did know about the identity of
objects, but my curiosity is based on the 256 number. Are the 2^8
integers cached due to the internal loops, or is there any other
specific reason? Is this something that can be controlled?
Jun 27 '08 #2
mi*************@gmail.com wrote:
On Jun 20, 9:38 am, Jean-Paul Calderone <exar...@divmod.comwrote:
>On Fri, 20 Jun 2008 09:31:57 -0700 (PDT), michalis.avr...@gmail.com wrote:
>>I am not certain why this is the case, but...

>a = 256
>b = 256
>a is b
>>
True

>a = 257
>b = 257
>a is b
>>
False

Can anyone explain this further? Why does it happen? 8-bit integer
differences?
http://mail.python.org/pipermail/pyt...er/113994.html

Jean-Paul

Thank you for this Jean-Paul. I did know about the identity of
objects, but my curiosity is based on the 256 number. Are the 2^8
integers cached due to the internal loops, or is there any other
specific reason? Is this something that can be controlled?
Python provides no way to change that number, but of course you can
always fiddle with the source code and recompile. The actual value is
a trade off (like any caching scheme) of cache-space versus efficiency
gains. The value has changed at least once in recent versions of Python.

Gary Herron
--
http://mail.python.org/mailman/listinfo/python-list
Jun 27 '08 #3
On Jun 21, 2:14*am, Gary Herron <gher...@islandtraining.comwrote:
michalis.avr...@gmail.com wrote:
On Jun 20, 9:38 am, Jean-Paul Calderone <exar...@divmod.comwrote:
On Fri, 20 Jun 2008 09:31:57 -0700 (PDT), michalis.avr...@gmail.com wrote:
>I am not certain why this is the case, but...
>>>>a = 256
b = 256
a is b
>True
>>>>a = 257
b = 257
a is b
>False
>Can anyone explain this further? Why does it happen? 8-bit integer
differences?
>http://mail.python.org/pipermail/pyt...er/113994.html
Jean-Paul
Thank you for this Jean-Paul. I did know about the identity of
objects, but my curiosity is based on the 256 number. Are the 2^8
integers cached due to the internal loops, or is there any other
specific reason? Is this something that can be controlled?

Python provides no way to change that number, but of course you can
always fiddle with the source code and recompile. * The actual value is
a trade off (like any caching scheme) of cache-space versus efficiency
gains. * The value has changed at least once in recent versions of Python.
And if your code breaks because of this, don't whine, 'cause you've
already been warned not to rely on it. Exactly the same arguments with
other people that is/going to whine because they break the
encapsulation.
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

### Similar topics

 36 by: Armin Rigo | last post by: Hi! This is a rant against the optimization trend of the Python interpreter. Sorting a list of 100000 integers in random order takes: * 0.75... 114 by: Maurice LING | last post by: This may be a dumb thing to ask, but besides the penalty for dynamic typing, is there any other real reasons that Python is slower than Java? ... 20 by: Wayne Sutton | last post by: OK, I'm a newbie... I'm trying to learn Python & have had fun with it so far. But I'm having trouble following the many code examples with the... 9 by: Lonnie Princehouse | last post by: There doesn't seem to be any way to customize the behavior of "is" as can be done for other operators... why not? 92 by: ureuffyrtu955 | last post by: Python is a good programming language, but "Python" is not a good name. First, python also means snake, Monty Python. If we search "python" in... 4 by: michalis.avraam | last post by: I am not certain why this is the case, but... True False Can anyone explain this further? Why does it happen? 8-bit integer differences? 0 by: Jean-Paul Calderone | last post by: On Fri, 20 Jun 2008 10:07:56 -0700 (PDT), George Sakkis