Name
__eq__, __ge__, __gt__, __le__, __lt__, __ne__
Synopsis
__eq__(self,other) __ge__(self,other) __gt__(self,other) __le__(self,other) __lt__(self,other) __ne__(self,other)
Comparisons x
==
y,
x
>=
y, x
>
y, x
<=
y, x
<
y, and
x
!=
y,
respectively, call the special methods listed here, which should
return False or True (in Python
2.2.1 and later; 0 or 1 in
Python 2.2, 2.1, and earlier). Each method may return
NotImplemented to tell Python to handle the
comparison in alternative ways (e.g., Python may then try
y
>
x
in lieu of
x
<
y).
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access