While reviewing some Python code, I encountered some bad logic. But, I don't understand how it is getting evaluated. The code amounts to this:
>>> "foo" in "bar" != "baz"
False
How is this False? The "in" and "!=" have the same order of precedence. If the "in" is evaluated first:
>>> ("foo" in "bar") != "baz"
True
because False is not equal to "baz". But if "!=" has precedence, then this should raise an exception:
>>> "foo" in ("bar" != "baz")
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
"foo" in ("bar" != "baz")
TypeError: argument of type 'bool' is not iterable
So, for the first example, without parentheses, what is going on?