Can someone explain to me why the Python interpreter evaluates this expression to be False?
1 in [1] == True
Run Code Online (Sandbox Code Playgroud)
I would expect that 1 in [1] would evaluate to True, and obviously True == True would be True. However this isn't what happens - the expression is False. Why does this happen?
int*_*jay 11
==
并且in
都是比较运算符。并且当您有多个这样的比较运算符时,Python会将其视为链式比较。例如,1 < x < 10
等效于1 < x and x < 10
。
就您而言,1 in [1] == True
等于(1 in [1]) and ([1] == True)
,其结果为False
。