0

I would like to understand how parsing in Python works. More specifically, how can these three statements give three different results :

0 in [0] is True 
# returns False
(0 in [0]) is True 
# returns True
0 in ([0] is True)
# raises TypeError

while only two different results are obtained with

1 == 1 is True 
# returns False
(1 == 1) is True 
# returns True
1 == (1 is True)
# returns False
Kokli
  • 155
  • 7
  • 1
    Try `[0] is True`. That's not where the `TypeError` is—it's the `0 in` the result of `[0] is True`. – ChrisGPT was on strike Apr 21 '20 at 18:56
  • 3
    So, `is` and `in` are both [comparison operators](https://docs.python.org/3/reference/expressions.html#comparisons) so they are chained, just like `<`. so you can write `x < y < z` in python, and that is equivalent to `x < y) and (y < z)`, similarly, `0 in [0] is True` is equivalent to `(0 in [0]) and ([0] is True)` – juanpa.arrivillaga Apr 21 '20 at 18:56

0 Answers0