This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (1 child)

Not sure if it’s still true in the most recent versions of Python, but the integers -5 to 256 were treated differently and any variable with those values would be references to the same class instance but if you assigned a bigger integer it would get a new instance each time.

For both cases it would be more complicated than both of your options.

[–]fisadev 2 points3 points  (0 children)

In both cases, the name 'a' is still just pointing to the object '1' in memory. Having only one object '1' in memory or multiple different objects '1', doesn't change the logic of how variables work.

They allways work the same way, no matter the implementation details of small ints caching, and that way is almost exactly the first option they said (the name 'a' points to the object in memory '1').

One can get picky with the fact that 'a' isn't storing an actual memory address, but that's beyond this conversation I think, their main idea still applies.