
Why 256 is 256, but 512 is not 512 in Python
In Python, two variables equal to 256 share the same object, but two variables equal to 512 don’t. The reason is Python’s object model. In this chapter, we cover identity, type, and value; how assignment and name binding actually work; the small-integer cache; and why mutating a list changes both aliases while reassigning a string doesn’t.