`3 > 2 == True` 返回 False? [重复]

问题描述 投票:0回答:1

我在笔记本电脑上尝试了一个表达式

3 > 2 == True

输出为

False
?

python python-3.x math
1个回答
1
投票

这称为链式比较

来自文档:比较

比较可以任意链接,例如 x < y <= z is equivalent to x < y and y <= z, except that y is evaluated only once (but in both cases z is not evaluated at all when x < y is found to be false).

所以等式变为:

3 > 2  and 2 == True
True and False
False
© www.soinside.com 2019 - 2024. All rights reserved.