Lesson

Difference between Equality Operator and Identity Operator in Python

Use the equality operator to compare the values of the objects. Identity operator is used to verifying that objects are equal but are not referring to the same object in memory.

Duration
2 min
Access
Free
Transcript
Available

Use the equality operator to compare the values of the objects. Identity operator is used to verifying that objects are equal but are not referring to the same object in memory.

Use cases where identity operator is used are:

  • to test if the object is None
  • to test if the object is of a particular type or not

There may be use cases where the output returned by both the operators is the same. But, in your program, you have used the identity operator instead of the equality operator.

To avoid such mistakes it is important to understand the difference between identity and equality operator.