题解 | 重载运算

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-01 21:50
已编辑
天津理工大学 Java
点赞 评论 收藏
分享
07-07 11:33
江南大学 Java
已经在暑假实习了 ,没有明确说有hc,纠结实习到八月份会不会有点影响秋招毕竟感觉今年好多提前批
程序员小白条:92的话准备提前批,其他没必要,没面试机会的,而且你要准备充分,尤其八股和算法题
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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