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

anonymity
Release: 2020-09-18 10:56:15
Original
4643 people have browsed it

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
Copy after login

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

(1 in [1, 0]) and ([1, 0] == True)
Copy after login

which is obviously False.

This also works for expressions like

a < b < c
Copy after login

converts to

(a < b) and (b < c)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template