Python: Identity Operators

Identity operators are used to check the objects, not if they are equal, but if they are actually the same object, with the same memory location.

OperatorDescriptionSyntax
is If both operands are identical. Returns True.a is b
is notIf both operands are not identical. Returns True.a is not b

Example:

a = 4
b = 4

print(a is b)
print(a is not b)

x = [1,2,3]
y = [1,2,3]

print(x is y)
print(x is not y)

Output:

True
False
False
True
Tags