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: ~True is not False
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 2.7, Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, anacrolix, loewis, vstinner
Priority: normal Keywords:

Created on 2011-06-30 05:45 by anacrolix, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg139458 - (view) Author: Matt Joiner (anacrolix) Date: 2011-06-30 05:45
Given there is no ! operator in Python, I next tried ~ (despite that I'm after a logical not). This came as a surprise:

>>> bool(~True)
True
>>> bool(~False)
True
>>> bool(~~False)
False
>>> ~True, ~~True, ~False, ~~False
(-2, 1, -1, 0)

Is there any consideration to "fixing" this? Is int(True) 1 due to C? Why is it preferred over -1?

It seems more appropriate to me that True have:

def __invert__(self): return False
def __int__(self): return 1 # or even -1

This also "fixes" this case too:

>>> -True
-1
msg139459 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011-06-30 05:51
Did you try the "not" operator?
http://docs.python.org/reference/expressions.html#boolean-operations

>>> not True
False
>>> not False
True
msg139460 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2011-06-30 06:11
This is deliberate, and will not be changed (at least not until Python 4, and likely not even then). Please ask on a Python forum about history and motivation of the boolean type in Python if you want to know more.
msg349538 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-08-13 10:23
bpo-37831 has been marked as a duplicate of this issue.
History
Date User Action Args
2022-04-11 14:57:19adminsetgithub: 56656
2019-08-13 10:23:05vstinnersetnosy: + vstinner
messages: + msg349538
2019-08-12 15:28:50josh.rlinkissue37831 superseder
2011-06-30 06:11:08loewissetstatus: pending -> closed
nosy: + loewis
messages: + msg139460

2011-06-30 05:51:45amaury.forgeotdarcsetstatus: open -> pending

nosy: + amaury.forgeotdarc
messages: + msg139459

resolution: not a bug
2011-06-30 05:45:41anacrolixcreate