IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

Comparable

A type which can be compared for order with other instances of itself.

Implementers of this trait must define the __lt__ and __eq__ methods.

The default implementations of the default comparison methods can be potentially inefficient for types where comparison is expensive. For such types, it is recommended to override all the default implementations.

Implemented traits

AnyType, Equatable

Required methods

__lt__

def __lt__(self, rhs: Self) -> Bool

Define whether self is less than rhs.

Args:

  • rhs (_Self): The value to compare with.

Returns:

Bool: True if self is less than rhs.

Provided methods

__le__

def __le__(self, rhs: Self) -> Bool

Define whether self is less than or equal to rhs.

Args:

  • rhs (_Self): The value to compare with.

Returns:

Bool: True if self is less than or equal to rhs.

__gt__

def __gt__(self, rhs: Self) -> Bool

Define whether self is greater than rhs.

Args:

  • rhs (_Self): The value to compare with.

Returns:

Bool: True if self is greater than rhs.

__ge__

def __ge__(self, rhs: Self) -> Bool

Define whether self is greater than or equal to rhs.

Args:

  • rhs (_Self): The value to compare with.

Returns:

Bool: True if self is greater than or equal to rhs.