class Rest:
def __init__(self, a, b):
self.a = a
self.b = b
def __str__(self):
return "Rest({},{})".format(self.a, self.b)
def __add__(self, other):
return Rest(self.a + other.a, self.b + other.b)
print(Rest(1, 2) + Rest(4, 6))
运算符重载(加操作)
最新推荐文章于 2024-06-14 23:48:57 发布