What is "is not" operator in Python?

In Python is not membership operator evaluates to false if the variables on either side of the operator point to the same object and true otherwise. For example −

>>> a = 10
>>> b = 20
>>> id(a), id(b)
(1581561184, 1581561504)
>>> a is not b

Since id() of variables a and b are different is not operator returns true.

Kickstart Your Career

Get certified by completing the course

Get Started