(Mar-28-2018, 09:29 AM)aaron1989041 Wrote: i think if id() function gives the same address for two objects,they must be the same object.Use code tags.
There not same object,but something strange happens when making into a tuple object.
>>> class A: ... pass ... ... class B: ... pass >>> id(A.__dict__) 62085776 >>> id(B.__dict__) 62373680So when use
,
between object,Python is making a tuple.This is when the somewhat strange execution happens.
>>> id(A.__dict__), id(B.__dict__) (136355152, 136355152)It look like when using special method in tuple creation it call same object.
>>> a = 'foo' >>> b = 'bar' >>> id(a) 128252192 >>> id(b) 61876128 >>> id(a), id(b) (128252192, 61876128)Using
.__add__
the same happens.>>> id(a.__add__), id(b.__add__) (62304752, 62304752)Nothing to worry about,
this is some internal stuff with
id()
and special method
in tuple creation.