Comparing Objects

Here, you'll learn how to compare different objects with one another in Python

Comparing objects in Python

The equality (==) and inequality (!=) operators work well with Python’s built-in object types. However, when you define your own classes, == will always return False when comparing two objects.

When we talk about drawing comparison between two objects, it is important to keep in mind the distinction between equal and identical.

  • Two objects, a and b, are equal if every part of a is the same as the corresponding part of b. If you change a, b might or might not change. Testing for equality requires testing all the parts.

  • However, if a and b are ...