Reputation: 107
Why am I getting two different memory addresses for the same object?
Upvotes: 2
Views: 263
Reputation: 3519
x
inside class __init__
should give error. Your code is running because you are using IDE like syder/jupyter which store previously run code's result. If you restart your IDE and run same code again it will raise error name 'x' is not defined
x
(object of class) use self to get that reference.>>> class test:
... def __init__(self, max):
... print(self, "b")
...
>>> x = test(2)
<__main__.test object at 0x0000016A080052C8> b
>>> print(x,"a")
<__main__.test object at 0x0000016A080052C8> a
x
and self
inside __init__
have same address.Upvotes: 2