On Mon, Feb 22, 2021 at 10:11:14PM -0300, Soni L. wrote:

> Currently ~False is -1 and ~True is -2. Would be nicer if ~bool was the 
> same as not bool.

That's your opinion. I disagree.

Bitwise-not is not the same thing as boolean-not, and they should not be 
spelled the same, especially not when that would break the invariant 
that if `a == b` then `~a == ~b`.

>>> 0 == False
True
>>> ~0 == ~False
True


If you want boolean-not, then use the boolean-not operator `not`.


> In particular, this is nice for xnor operator: a ^~ b. This currently 
> works on ints, but not on bools

If it works on ints, of course it works on bools, because bools are 
ints. You get identical results whether you use int (0, 1) or bools 
(False, True) in every combination:


>>> def xnor(a, b):
...     return a ^ ~b
... 
>>> [xnor(a, b) for a in (0, 1) for b in (0, 1)]
[-1, -2, -2, -1]
>>> [xnor(a, b) for a in (0, 1) for b in (False, True)]
[-1, -2, -2, -1]
>>> [xnor(a, b) for a in (False, True) for b in (0, 1)]
[-1, -2, -2, -1]
>>> [xnor(a, b) for a in (False, True) for b in (False, True)]
[-1, -2, -2, -1]


-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/66NH5YKXRIWQWWKOZ6UHW37U55TS2F3Z/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to