Comparing Objects
Here, you'll learn how to compare different objects with one another in Python
We'll cover the following...
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
andb
, are equal if every part ofa
is the same as the corresponding part ofb
. If you changea
,b
might or might not change. Testing for equality requires testing all the parts. -
However, if
a
andb
are ...