题解 | #重载运算#
重载运算
https://www.nowcoder.com/practice/342d1b8b0fe3416797bad62d22cbb51a
class Coordinate: def __init__(self, x, y): self.x = x self.y = y def __add__(self): self.x = x1 + x2 self.y = y1 + y2 def __str__(self): print("({}, {})".format(self.x,self.y)) x1, y1 = map(int, input().split()) x2, y2 = map(int, input().split()) c = Coordinate(x1, y1) c.__add__() c.__str__()
看到一个大佬写的,感觉比较好理解