I have a class. created a two different object from the class. if we print the object it should return same address. Could anyone explain it is possible or not.
<code>class A:
def __init__(self):
pass
obj1=A()
obj2=A()
print(obj1)
print(obj2)
</code>
<code>class A:
def __init__(self):
pass
obj1=A()
obj2=A()
print(obj1)
print(obj2)
</code>
class A:
def __init__(self):
pass
obj1=A()
obj2=A()
print(obj1)
print(obj2)
Output:
<main.A object at 0x000001AEE78F3A90>
<main.A object at 0x000001AEE79E54F0>
Note: Both should print same address of class A. (It is an interview question.)
New contributor
Dilip is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2