class MyClass(): def __init__(self,p,q,r): self.a=p self.b=q self.c=r def __eq__(self,other): return self.__dict__ == other.__dict__ objA=MyClass("AA",2,3) objB=MyClass("AA",2,3) objC=MyClass("AA",2,6) print objA == objB print objA == objC
Output:
True False
class MyClass(): def __init__(self,p,q,r): self.a=p self.b=q self.c=r def __eq__(self,other): return self.b == other.b and self.c == other.c objA=MyClass("AEA",2,3) objB=MyClass("AA",2,3) objC=MyClass("AA",2,6) print objA == objB print objA == objC
Output:
True False
0 comments:
Post a Comment