题解 | 重载运算

class Coordinate:
    def __init__(self,x,y) -> None:
        self.x = x
        self.y = y

    def __str__(self) -> str:
        return f'({self.x}, {self.y})'

    def __add__(self,other):
        return Coordinate(self.x+other.x,self.y+other.y)

list1 = [int(i) for i in input().split()]
list2 = [int(i) for i in input().split()]
c1 = Coordinate(list1[0],list1[1])
c2 = Coordinate(list2[0],list2[1])
c = c1.__add__(c2)
print(c.__str__())

全部评论

相关推荐

06-12 16:23
已编辑
小米_软件开发(准入职员工)
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务