Strange chained comparison [duplicate]

ⅰ亾dé卋堺 提交于 2021-02-10 06:22:21

问题


>>> a = 2
>>> b = 3
>>> c = 2
>>> b > a == c
True
>>>

Is this true that b > a == c is equal to a < b and c == a because it's a chained comparison?

This doesn't make sense to me because of == comparison, I would expect that b > a == c is equal to (b > a) == c or b > (a == c).


回答1:


python is correcting your comparison automatically with if (b>a) AND (a==c)



来源:https://stackoverflow.com/questions/58084423/strange-chained-comparison

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!