📜  python运算符重载处理类型 - Python代码示例

📅  最后修改于: 2022-03-11 14:47:13.282000             🧑  作者: Mango

代码示例1
def __add__(self, other):
    if isinstance(other, self.__class__):
        return self.x + other.x
    elif isinstance(other, int):
        return self.x + other
    else:
        raise TypeError("unsupported operand type(s) for +: '{}' and '{}'").format(self.__class__, type(other))