Logo

Question preview

Small Integer Caching

What this preview is

About this preview

Small Integer Caching is a easy quant interview question on language knowledge in Python.

Unlock full access to getcracked

Join to unlock this question, detailed solutions, and our complete library of quant finance interview prep.

Understanding Python's small integer caching mechanism

This is an easy Python language-knowledge question that tests whether you understand how the interpreter optimises memory and object reuse under the hood. It probes your familiarity with Python's runtime behaviour—the kind of detail that surfaces in code reviews, debugging sessions, and deeper technical conversations.

Python caches certain immutable objects to improve performance and reduce memory overhead. Small integers are a canonical example: rather than creating a new object each time a literal or expression evaluates to a common small integer, the interpreter reuses a pre-allocated pool. Knowing this range matters when reasoning about object identity (the is operator) versus equality (the == operator), and helps explain why identity checks sometimes behave counterintuitively in interactive sessions versus scripts.

  • Object identity vs. equality in Python
  • Immutable object pooling and interning
  • How interpreter optimisations affect is-comparisons