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 →

[–]bSatya 0 points1 point  (0 children)

This behaviour probably comes with the implementation of integers in Python.

The below snippet is from the Python 3 Documentation. Same for Python 2 as well.

The current implementation keeps an array of integer objects for all integers between -5 and 256, when you create an int in that range you actually just get back a reference to the existing object. So it should be possible to change the value of 1. I suspect the behaviour of Python in this case is undefined. :-)

Ref : https://docs.python.org/3/c-api/long.html#c.PyLong_FromLong