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

and is not a logical conjugation #55946

Closed
theiain mannequin opened this issue Apr 1, 2011 · 2 comments
Closed

and is not a logical conjugation #55946

theiain mannequin opened this issue Apr 1, 2011 · 2 comments

Comments

@theiain
Copy link
Mannequin

theiain mannequin commented Apr 1, 2011

BPO 11737
Nosy @ezio-melotti

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 2011-04-01.14:35:00.302>
created_at = <Date 2011-04-01.14:22:55.520>
labels = ['invalid']
title = 'and is not a logical conjugation'
updated_at = <Date 2011-04-01.14:35:00.279>
user = 'https://bugs.python.org/theiain'

bugs.python.org fields:

activity = <Date 2011-04-01.14:35:00.279>
actor = 'ezio.melotti'
assignee = 'none'
closed = True
closed_date = <Date 2011-04-01.14:35:00.302>
closer = 'ezio.melotti'
components = []
creation = <Date 2011-04-01.14:22:55.520>
creator = 'the_iain'
dependencies = []
files = []
hgrepos = []
issue_num = 11737
keywords = []
message_count = 2.0
messages = ['132740', '132741']
nosy_count = 2.0
nosy_names = ['ezio.melotti', 'the_iain']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue11737'
versions = ['Python 2.7']

@theiain
Copy link
Mannequin Author

theiain mannequin commented Apr 1, 2011

The documentation here: http://docs.python.org/library/stdtypes.html
indicates that and operates as such
{if x:
return x
else:
return y}

to be a logical conjugation it should function as
{if x:
if y:
return True
return False}

The it is now (False and True) will return True. Basic logic asserts that this is not the case.

@ezio-melotti
Copy link
Member

The doc0 says:
"""
x and y: if x is false, then x, else y
"""
Boolean operators in Python always return one of the two values (rather than True/False), and they are also short-circuit operators, so:

  • if x is false, the whole expression is false regardless of the value of y, so x is returned without evaluating y;
  • if x is true, y could be either:
    • true: so the whole expression is true and y is returned;
    • false: so the whole expression is false and y is returned;
>>> '' and True
''
>>> True and ''
''
>>> True and 15
15

The behavior matches the documentation and (False and True) returns False, because x (False in this case) is false.

@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