Issue 14247: "in" operator doesn't return boolean (original) (raw)

In operator acts like it doesn't return a boolean value

3 in [1,2,3] == True False

and even

3 in [1,2,3] == 3 in [1,2,3] False

but somehow if you add ( ) it starts working

(3 in [1,2,3]) == True True

Tested on OSX 10.7 Python 2.7.1

Chaining comparison operators inserts implicit "and" conditions:

a OP b OP c OP d

is equivalent to

(a OP b) and (b OP c) and (c OP d)

This is most useful with ==, <, <= and so forth, but "in" and "is" also count as comparison ops and have the same precedence.