Account
Categories

IS NOT Operator (is not) in Python


Definition:

It checks whether the two variables do not point to the same memory location. If they do not, it returns True. Otherwise, it returns False.

Now you will clearly understand with the help of the diagram.

a (variable) ────────────────┐
                             ↓
                        ┌───────────┐
                        │   1, 2    │  ← (memory / object A)
                        └─────↑─────┘
                              │
                            value 

b (variable) ────────────────┐
                             ↓
                        ┌───────────┐
                        │   1, 2    │  ← (memory / object B)
                        └─────↑─────┘
                              │
                            value 

Syntax:

a is not b

Example:

a = [1, 2]
b = [1, 2]

print(a is not b)

Output:

Exercise

a = [1, 2] and b = [1, 2]. Check whether a is not b.