python grmph

apparently small ints are Special

>>> a = 256
>>> b = 256
>>> a == b
True
>>> a is b
True
>>> a = 257
>>> b = 257
>>> a == b
True
>>> a is b
False

4 Responses to “python grmph”

  1. doik says:

    that sort of even makes sense maybe. this does not:

    >>> a = -5

    >>> b = -5

    >>> a is b

    True

    >>> a = -6

    >>> b = -6

    >>> a is b

    False

    >>> a = -6; b = -6

    >>> a is b

    True

  2. cakesniffer says:

    Does sort of: it’s caching immutable small int objects and handing you back a reference to an existing one rather than creating loads of separate objects for every “1”. Then it pre-fills the cache with -5..255 which are presumably the most common.

  3. cakesniffer says:

    On second thoughts, that isn’t actually supported by the above example. Maybe it doesn’t make sense.

  4. blodgett says:

    transparency not python strong suit rly

Leave a Reply