Skip to main content

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.

Operator Description Syntax
is  If both operands are identical. Returns True. a is b
is not If 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
Submitted by devanshi.srivastava on June 25, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.