Predict Integer Caching
Advanced · Predict the output · from How Python Works Under the Hood: Memory, GIL, and Bytecode
From the lesson: How Python Works Under the Hood: Memory, GIL, and Bytecode
Every time you type x = 42, a lot happens behind the scenes. Python creates an integer object in memory, assigns a reference to it, and manages its lifecycle automatically. Understanding these internals doesn't just satisfy curiosity -- it helps you write faster code, debug memory issues, and nail technical interviews.
Read the lessonWhat does the following code print?
a = 100
b = 100
print(a is b)
x = [1, 2]
y = [1, 2]
print(x is y)a = 100
b = 100
print(a is b)
x = [1, 2]
y = [1, 2]
print(x is y)
More Internals exercises
- Disassemble a FunctionAdvanced
- Count ReferencesAdvanced
- Slots vs Dict MemoryAdvanced
- Fix the Identity BugAdvanced
All Python exercises · 50 practice problems · Advanced Python quiz