This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: "in" operator doesn't return boolean
Type: Stage:
Components: None Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Damjan.Košir, georg.brandl
Priority: normal Keywords:

Created on 2012-03-10 18:01 by Damjan.Košir, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg155329 - (view) Author: Damjan Košir (Damjan.Košir) Date: 2012-03-10 18:01
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
msg155332 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2012-03-10 18:11
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.
History
Date User Action Args
2022-04-11 14:57:27adminsetgithub: 58455
2012-03-10 18:11:06georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg155332

resolution: not a bug
2012-03-10 18:01:02Damjan.Košircreate