为什么我无法重新定义__and__
运算符?
class Cut(object):
def __init__(self, cut):
self.cut = cut
def __and__(self, other):
return Cut("(" + self.cut + ") && (" + other.cut + ")")
a = Cut("a>0")
b = Cut("b>0")
c = a and b
print c.cut()
我想要 (a>0) && (b>0)
,但是我只得到了 b,这是 and
的通常行为。