MemotivaVariables, references, and memory model

What is small integer caching in Python?

Variables, references, and memory model

Audio flashcard · 0:16

Nortren·

What is small integer caching in Python?

0:16

CPython caches small integers in the range from negative five to two hundred fifty six. Two variables assigned to the integer 100 will be the same object in memory, while two variables assigned to 1000 may not be. This is an implementation detail and should never be relied upon for program logic.
docs.python.org