How can this be possible in Python 3? k1 and k2's a attributes refer to the same memory location in IPython console
class K():
def __init__(self, a):
self.a = a
k1 = K(4)
k2 = K(4)
hex(id(k1)) # 0x10d77b668
hex(id(k2)) # 0x10d77b6a0
hex(id(k1.a)) # 0x10d41caa0
hex(id(k2.a)) # 0x10d41cac0
id(k1.a) == id(k2.a) # True
I am mostly concerned about the object reference issue going on here rather than the 'is' operator test, which I believe is not the problem I am trying to solve. Because, both k1.a and k2.a would pass the is test because the two references refer to the same object. But what I would like to know is, why that happens.