Python Bitwise NOT operator is denoted by ~. It Returns one’s compliment of the number. Bitwise operator normally working on bits(0’s and 1’s)
Bitwise NOT operator in Python
Simple example code inverts each bit from the binary representation of integer x
so that 0 becomes 1 and 1 becomes 0. This is semantically the same as calculating ~x == -x-1
. For example, the bitwise NOT expression ~0
becomes -1
, ~9
becomes -10
, and ~32
becomes -33
.
x = 0
print(~x)
x = 9
print(~x)
x = 32
print(~x)
Output:

Note: first the number is converted to binary then processed.
Do comment if you have any doubts or suggestions on this Python operator topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.