1

I've noticed some odd behavior when comparing booleans:

>>> '1' in '123'
True
>>> '1' in '123' == True
False

I thought that maybe it's an issue related to order of operations, but

>>> '1' in ('123' == True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: argument of type 'bool' is not iterable
>>> ('1' in '123') == True
True

Or that maybe x in y didn't actually return a boolean value, but

>>> type('1' in '123') is type(True)
True

Can somebody explain this? Is it a bug? (Tested in python2.7 and python3.5.)

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
  • 1
    http://stackoverflow.com/a/33326230/1005215 – Nehal J Wani Aug 18 '16 at 09:09
  • 1
    [Note that comparisons, membership tests, and identity tests, all have the same precedence and have a left-to-right chaining feature.](https://docs.python.org/3/reference/expressions.html#operator-precedence) – Mazdak Aug 18 '16 at 09:19
  • And as a more complete explanation about operations precedence read this answer of mine http://stackoverflow.com/a/31458009/2867928 – Mazdak Aug 18 '16 at 09:21

0 Answers0