Re: Python "is" behavior

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jean-Paul Calderone

    Re: Python "is" behavior

    On Fri, 20 Jun 2008 09:31:57 -0700 (PDT), michalis.avraam @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?


    Jean-Paul
  • michalis.avraam@gmail.com

    #2
    Re: Python "is&quo t; behavior

    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?
    >

    >
    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?

    Comment

    • Gary Herron

      #3
      Re: Python &quot;is&quo t; behavior

      michalis.avraam @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

      Comment

      • Lie

        #4
        Re: Python &quot;is&quo t; behavior

        On Jun 21, 2:14 am, Gary Herron <gher...@island training.comwro te:
        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?
        >>
        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.

        Comment

        Working...