In Python:
>>> a = "Hello"
>>> b = "Hello"
>>> id(a) == id(b)
True
Why? Can this create a problem in a complex programs which refer to the memory locations of the object?
In Python:
>>> a = "Hello"
>>> b = "Hello"
>>> id(a) == id(b)
True
Why? Can this create a problem in a complex programs which refer to the memory locations of the object?
For immutable types [like strings], operations that compute new values may actually return a reference to any existing object with the same type and value. E.g., after
a = 1; b = 1
,a
andb
may or may not refer to the same object with the value one, depending on the implementation...