Name
__cmp__
Synopsis
__cmp__(self,other
)
Any comparison, when its specific special method (__lt__
, __gt__
, etc.) is absent or returns
NotImplemented
, calls
x
.__cmp__(
y
)
instead,
as do built-in function
cmp(
x
,y
)
and the sort
method of list objects. __cmp__
should return -1
if
x
is less than
y
, 0
if
x
is equal to
y
, or 1
if
x
is greater than
y
. When __cmp__
is
also absent, order comparisons (<
,
<=
, >
,
>=
) raise exceptions. Equality comparisons
(= =
, !=
), in this case, become
identity checks: x
==
y
evaluates
id(
x
)==id(
y
)
(i.e.,
x
is
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.