Interned Objects

These are the cached PyObjects which python does for optimizations and performance.

  1. All integers -5 to 255 are cached.
  2. Strings that contain ASCII letters, digits, or underscores only.

For example,

a = 1
b = 1
 
a is b # True
 
sys.getrefcount(a)
sys.getrefcount(b)
 
# both gives same result

Both a and b points to the same Python Object (PyObject).

References

  1. https://realpython.com/pointers-in-python/#a-note-on-intern-objects-in-python