nin*_*o64 1 python operator-overloading caret
我需要覆盖类中的插入符行为,但我不确定哪个操作符重载适用于它.例如:
class A:
def __init__(self, f):
self.f = f
def __caret__(self, other):
return self.f^other.f
print A(1)^A(2)
Run Code Online (Sandbox Code Playgroud)
此代码错误:
TypeError: unsupported operand type(s) for ^: 'instance' and 'instance'
Run Code Online (Sandbox Code Playgroud)
我如何构建类以便控制行为?