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).
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