Functional Functions

functools.total_ordering()

Fill in missing ordering methods on a class defining equality and at least one ordering operation. Existing methods are not replaced.

Formal Syntax & Structure

python syntaxpython
functools.total_ordering(cls)

Parameters & Attributes

NameTypeDescription
clstypeClass to decorate.

Return Value

type

The type result described above.

Working Example

Example Snippetpython
import functools@functools.total_orderingclass Rank: def __init__(self,n): self.n=n def __eq__(self,other): return self.n==other.n if isinstance(other,Rank) else NotImplemented def __lt__(self,other): return self.n<other.n if isinstance(other,Rank) else NotImplementedprint((Rank(1)<=Rank(2),Rank(2)>Rank(1)))
Python Reference