Home > Software engineering >  What's the difference between not and ~ in python
What's the difference between not and ~ in python

Time:01-24

Just to check, I couldn't find anything about ~, so I want to make sure it's the same.

Also, can you use ! in python like in C ?

It seems that these two codes give the same output:

bool(~0)
bool(not 0)

CodePudding user response:

This is how it is in Python.

'~' is a bitwise operator

whereas 'not' is a logical opeartor

CodePudding user response:

You should read Python 3.10 documentation at Unary arithmetic and bitwise operations.


The ~ operator does a simple job:

Inverts the bits

  •  Tags:  
  • Related