Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"in" operator doesn't return boolean #58455

Closed
DamjanKoir mannequin opened this issue Mar 10, 2012 · 2 comments
Closed

"in" operator doesn't return boolean #58455

DamjanKoir mannequin opened this issue Mar 10, 2012 · 2 comments

Comments

@DamjanKoir
Copy link
Mannequin

DamjanKoir mannequin commented Mar 10, 2012

BPO 14247
Nosy @birkenfeld

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2012-03-10.18:11:06.673>
created_at = <Date 2012-03-10.18:01:02.115>
labels = ['invalid']
title = '"in" operator doesn\'t return boolean'
updated_at = <Date 2012-03-10.18:11:06.671>
user = 'https://bugs.python.org/DamjanKoir'

bugs.python.org fields:

activity = <Date 2012-03-10.18:11:06.671>
actor = 'georg.brandl'
assignee = 'none'
closed = True
closed_date = <Date 2012-03-10.18:11:06.673>
closer = 'georg.brandl'
components = ['None']
creation = <Date 2012-03-10.18:01:02.115>
creator = 'Damjan.Ko\xc5\xa1ir'
dependencies = []
files = []
hgrepos = []
issue_num = 14247
keywords = []
message_count = 2.0
messages = ['155329', '155332']
nosy_count = 2.0
nosy_names = ['georg.brandl', 'Damjan.Ko\xc5\xa1ir']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue14247'
versions = ['Python 2.7']

@DamjanKoir
Copy link
Mannequin Author

DamjanKoir mannequin commented Mar 10, 2012

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

@birkenfeld
Copy link
Member

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.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant