Python Tilde Operator

tilde operator may not work as you expected

~ in python will invert the value. The actual method depends on the implementation of __invert__ method of the argument.

Let’s start with the numbers.

~10 # -11
~-10 # 9

~1 # -2
~-1 # 0

~0 # -1

The case for True and False

~True # -2
~False # -1

# which are the same as
~1 # -2
~0 # -1

Planted: by ;

L Ma (2019). 'Python Tilde Operator', Datumorphism, 08 April. Available at: https://datumorphism.leima.is/til/programming/python/python-tilde-operator/.