How to: Why does ~True result in -2?
How to: Why does ~True result in -2?
Why does ~True result in -2?
In Python console:
~True
Gives me:
-2
Why? Can someone explain this particular case to me in binary?
Answer: Why does ~True result in -2?
The Python bool type is a subclass of int (for historical reasons; booleans were only added in Python 2.3).
Since int(True) is 1, ~True is ~1 is -2.
See PEP 285 for why bool is a subclass of int.
If you wanted the boolean…
View On WordPress















