python 是否短路 bool 值,如 a==b==c
,即,如果 a==b
为假,则不评估第二个相等性?复合相等性只是 a==b 和 b==c
的语法糖吗?
最佳答案
是的。来自docs :
Comparisons can be chained arbitrarily, e.g.,
x < y <= z
is equivalent tox < y
andy <= z
, except thaty
is evaluated only once (but in both casesz
is not evaluated at all whenx < y
is found to be false).
这适用于任何链式比较,与选择的比较运算符无关。
关于python - 复合相等性测试在 python 中短路了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59312361/