Home >Backend Development >Python Tutorial >Why the expression 'in [1,0] == True' evaluates to false

Why the expression 'in [1,0] == True' evaluates to false

anonymity
anonymityOriginal
2019-05-24 13:37:594647browse

The reason why the execution result of the expression "in [1,0] == True" is false: [==] in the expression is equivalent to and, that is, [(1 in [1, 0]) and ([1, 0] == True)].

Why the expression 'in [1,0] == True' evaluates to false

Why is the execution result of in [1,0] == True false?

Running in python found:

>>> 1 in [1,0] == True     # This is strangeFalse
>>> False

Python actually applies comparison operator chaining here. The expression is translated to

(1 in [1, 0]) and ([1, 0] == True)

which is obviously False.

This also works for expressions like

a < b < c

converts to

(a < b) and (b < c)

The above is the detailed content of Why the expression 'in [1,0] == True' evaluates to false. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn