我需要覆盖类中的插入符号行为,但我不确定哪个运算符重载适用于它。例如:
class A:
def __init__(self, f):
self.f = f
def __caret__(self, other):
return self.f^other.f
print A(1)^A(2)
此代码错误:
TypeError: unsupported operand type(s) for ^: 'instance' and 'instance'
如何构建类以便我可以控制行为?