题解 | #重载运算#

重载运算

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__()

看到一个大佬写的,感觉比较好理解

全部评论
点赞 回复 分享
发布于 2024-05-09 22:13 四川

相关推荐

04-03 12:09
東京大学 C++
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务