# 比较运算符
class demo6:
def __init__(self, num):
self.data = num
# <
def __lt__(self, other):
return self.data < other.data
# <=
def __le__(self, other):
return self.data <= other.data
# ==
def __eq__(self, other):
return self.data == other.data
# !=
def __ne__(self, other):
return self.data != other.data
# >
def __gt__(self, other):
return self.data > other.data
# >=
def __ge__(self, other):
return self.data >= other.data
【Python】 操作符重载
最新推荐文章于 2024-07-31 18:10:45 发布