python 对象值比较

class A:
    def __init__(self, t):
        self.t = t

    def __eq__(self, other):
        print(self.t)
        return self.t > 1
        return super(A, self).__lt__(other)


print(A(1) == A(2))

  输出

1
False

  调用两次eq方法,需要满足左边变量和右边变量方法的返回值均为真

猜你喜欢

转载自www.cnblogs.com/zjchen/p/11845903.html