2

Why am I getting two different memory addresses for the same object?

https://i.stack.imgur.com/UPY7p.png

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Anuvicleo
  • 107
  • 1
  • 7

1 Answers1

2
  • your 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
  • If you want to reference 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
Poojan
  • 3,366
  • 2
  • 17
  • 33