Python Identity Operators
Identity operators are used to compare the memory location of two objects, especially when both the objects have same name and can be differentiated only using its memory location. There are two Identity operators: "is" and "is not" .- is - Returns true if both variables are the same object.
- is not - Returns true if both variables are not the same object.

Python is operator
x = '101'
y = '101'
z = '102'
if (x is y):
print ('x is y')
else:
print ('x is not y')
if (x is z):
print('x is z')
else:
print ('x is not z')
if (y is z):
print('y is z')
else:
print ('y is not z')
output
x is y
x is not z
y is not z
Python is not Operator
x = '101'
y = '101'
z = '102'
if (x is not y):
print ('x is not y')
else:
print ('x not y')
if (x is not z):
print ('x is not z')
else:
print ('x is z')
if (y is not z):
print ('y is not z')
else:
print ('y is z')
output
x not y
x is not z
y is not z
Is there a difference between "==" and "is"?
The is operator will return True if two variables point to the same object, "==" if the objects referred to by the variables are equal: for example in this case num1 and num2 refer to an int instance storing the value 101:
num1 = 101
num2 = num1

Because num2 refers to the same object is and == will give True:
>>> num1 == num2
True
>>> num1 is num2
True
In the following example the names num1 and num2 refer to different int instances, even if both store the same integer:
>>> num1 = 101
>>> num2 = 101

Because the same value (integer) is stored == will return True, that's why it's often called value comparison . However is operator will return False because these are different objects :
>>> num1 == num2
True
>>> num1 is num2
False
You should only use is operator if you:
- want to check if two objects are really the same object (not just the same "value").
- want to compare a value to a Python constant.
- None
- True
- False
- NotImplemented
- Ellipsis
- __debug__
- classes (for example int is int or int is float)
Related Topics
- Keywords in Python
- Python Operator - Types of Operators in Python
- Python Variables and Data Types
- Python Shallow and deep copy operations
- Python Datatype conversion
- Python Mathematical Function
- Basic String Operations in Python
- Python Substring examples
- How to check if Python string contains another string
- Check if multiple strings exist in another string : Python
- Memory Management in Python
- What is a None value in Python?
- How to Install a Package in Python using PIP
- How to update/upgrade a package using pip?
- How to Uninstall a Package in Python using PIP
- How to call a system command from Python
- How to use f-string in Python
- Python Decorators (With Simple Examples)
- Python Timestamp Examples