2024/5/16

所花时间:1小时

代码行:70行

博客量:1篇

了解到的知识点:

import math

# 定义平面点类

class Point:

    def _init_(self, x, y):

        self.x = x

        self.y = y

    # 重载小于运算符

    def _lt_(self, other):

        distance_self = math.sqrt(self.x**2 + self.y**2)

        distance_other = math.sqrt(other.x**2 + other.y**2)

        return distance_self < distance_other

# 测试

point1 = Point(3, 4)

point2 = Point(1, 2)

if point1 < point2:

    print("point1比point2远")

else:

    print("point2比point1远")

posted @ 2024-05-16 19:15  为20岁努力  阅读(31)  评论(0编辑  收藏  举报