题解 | #重载运算#
重载运算
https://www.nowcoder.com/practice/342d1b8b0fe3416797bad62d22cbb51a
class Coordinate():
def __init__(self, x, y) -> None:
self.x = x
self.y = y
def __str__(self) -> str:
print(f'({self.x}, {self.y})')
return self.x, self.y
def __add__(c1, c2):
x = c1.x + c2.x
y = c1.y + c2.y
newC = Coordinate(x, y)
return newC
x1, y1 = input().split(' ')
x2, y2 = input().split(' ')
x1 = int(x1)
x2 = int(x2)
y1 = int(y1)
y2 = int(y2)
c1 = Coordinate(x1, y1)
c2 = Coordinate(x2, y2)
c3 = __add__(c1, c2)
c3.__str__()