小编Gui*_*tre的帖子

python total_ordering:为什么__lt__和__eq__而不是__le__?

在Python3中,functools.total_ordering装饰器允许只重载__lt____eq__获得所有6个比较运算符.

我不明白为什么一个人必须写两个运算符就足够了,即__le__或者__ge__,并且所有其他运算符都会相应地定义:

a < b   <=>   not (b <= a)
a > b   <=>   not (a <= b)
a == b   <=>   (a <= b) and (b <= a)
a != b   <=>   (a <= b) xor (b <= a)
Run Code Online (Sandbox Code Playgroud)

那是因为xor运算符本身不存在吗?

python comparison-operators python-3.x

11
推荐指数
1
解决办法
3258
查看次数

标签 统计

comparison-operators ×1

python ×1

python-3.x ×1