Home >Backend Development >Python Tutorial >Why does `(1 in [1,0] == True)` evaluate to `False` in Python?
False Evaluation of (1 in [1,0] == True)
Unlike a typical programming language, Python evaluates expressions using comparison operator chaining. In the expression (1 in [1,0] == True), the operation is not parsed as expected.
The expression is actually interpreted as:
(1 in [1, 0]) and ([1, 0] == True)
This evaluation breaks down into:
The overall expression, therefore, evaluates to:
True and False = False
This unexpected result highlights the difference in Python's evaluation of expressions compared to other languages. To avoid confusion, use parentheses to specify the desired evaluation order:
(1 in [1,0]) == True # True
The above is the detailed content of Why does `(1 in [1,0] == True)` evaluate to `False` in Python?. For more information, please follow other related articles on the PHP Chinese website!