Two objects created separately by calling the class cannot be termed as same by just passing the same values. The following example gives you the answer. Run to see.
class Test:
def __init__(self, a):
self.a = a
def pprint(self):
print(self.a)
obj1 = Test(5)
obj1.pprint()
obj2 = obj1
obj2.pprint()
obj3 = Test(5)
print("1 and 3 are same.") if obj1==obj3 else print("1 and 3 are NOT same.")
print("1 and 2 are same.") if obj1==obj2 else print("1 and 2 are NOT same.")
print("1 a and 3 a are same.") if obj1.a==obj3.a else print("1 a and 3 a are NOT same.")
print("1 a and 2 a are same.") if obj1.a==obj2.a else print("1 a and 2 a are NOT same.")
Comments
Post a Comment