What Does is Not Operator Do in Python



In Python, is and is not operators are called identity operators. Each object in computer's memory is assigned a unique identification number (id) by Python interpreter. Identity operators check if id() of two objects is same. 'is not' operator returns true of id() values are different and false if they are same.

>>> a=10
>>> b=a
>>> id(a), id(b)
(490067904, 490067904)
>>> a is not b
False
>>> a=10
>>> b=20
>>> id(a), id(b)
(490067904, 490068064)
>>> a is not b
True
Updated on: 2020-02-26T10:41:38+05:30

477 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements