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
).
Get Python in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.