TechToFreedom
Published in

TechToFreedom

3 Facts of the Integer Caching in Python

Understand some confusing results made by Python

3 Facts of the Integer Caching in Python
Photo by Ben White on Unsplash

Python has a special feature called integer caching, or integer interning. Sometimes, it may make us confused. For example, if we run the following code on a Python shell, the results are surprising:

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

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store