Possible Duplicate:
The tilde operator in Python
What does the squiggle i.e. ~
operator do in Python?
(This is probably Python 101 for most, but I came across ~
in code and had no idea what it was, and it took me a surprising amount of research to figure it out, so hopefully this Q&A can help someone down the road.)
It's the unary bitwise invert operator.
The unary
~
(invert) operator yields the bitwise inversion of its plain or long integer argument. The bitwise inversion ofx
is defined as-(x+1)
. It only applies to integral numbers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With