I (incorrectly?) used \'is not\' in a comparison and found this curious behavior:
>>> a = 256
>>> b = int(\'256\')
>>> c = 300
>>
For small numbers, Python is reusing the object instances, but for larger numbers, it creates new instances for them.
See this:
>>> a=256
>>> b=int('256')
>>> c=300
>>> d=int('300')
>>> id(a)
158013588
>>> id(b)
158013588
>>> id(c)
158151472
>>> id(d)
158151436
which is exactly why a
is b
, but c
isn't d
.