Someone just showed me this weird example of python syntax. Why is [4] working?
I would have expected it to evaluate to either [5] or [6], neither of which works. Is there some premature optimisation going on here which shouldn't be?
In [1]: s = 'abcd'
In [2]: c = 'b'
In [3]: c in s
Out[3]: True
In [4]: c == c in s
Out[4]: True
In [5]: True in s
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-e00149345694> in <module>()
----> 1 True in s
TypeError: 'in <string>' requires string as left operand, not bool
In [6]: c == True
Out[6]: False