6. Identity Operators

  • Identity operators are used to compare memory locations two objects to determine if they refers to the same object in memory. There are two identity operators in python. They are is and is not.

Operator

Description

Example

is

Returns True if the either side operands of the operator are referring to the same objects in memory. Otherwise, it returns False.

X=[1,2,3]

Y=X

X is Y - True

is not

Returns True if the operands on both sides of the operator are referring to the different objects in memory. Otherwise, it returns False.

X=[1,2,3]

Y=X

X is not Y - False