#coding=utf8 class A(object): def __init__(self, name): self.name = name def __eq__(self, obj): return self.name == obj.name if __name__ == '__main__': a = A("Leon") b = A("Leon") print a == b
__eq__ 定义了类的等号(==)行为
#coding=utf8 class A(object): def __init__(self, name): self.name = name def __eq__(self, obj): return self.name == obj.name if __name__ == '__main__': a = A("Leon") b = A("Leon") print a == b
__eq__ 定义了类的等号(==)行为