As the string id(A.__str__) == id(B.__str__)
is evaluated, A.__str__
is created, its id taken, and then garbage collected. Then B.__str__
is created, and happens to end up at the exact same address that A.__str__
was at earlier, so it gets (in CPython) the same id.
Try assigning A.__str__
and B.__str__
to temporary variables and you'll see something different:
>>> f = A.__str__
>>> g = B.__str__
>>> id(f) == id(g)
False
For a simpler example of this phenomenon, try:
>>> id(float('3.0')) == id(float('4.0'))
True
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…