Operators
<= — Less-than or equal
Tests non-strict ordering. For sets it means subset, allowing equality. For ordered built-in sequences it uses lexicographic comparison. Custom __le__ is independent of __lt__ and __eq__; implementing those two alone does not automatically implement <=. Rich comparisons share precedence and support chaining: the middle operand is evaluated once, and later operands are skipped when a preceding comparison is falsy. If both operands decline the comparison, ordering raises TypeError. Custom dispatch uses __le__ and the counterpart __ge__ on the other operand; a right-hand subclass may have priority.
Formal Syntax & Structure
python syntaxpython
left <= rightParameters & Attributes
| Name | Type | Description |
|---|---|---|
| left | object | First operand; its type participates in operation selection. |
| right | object | Second operand; supported values depend on the operand types. |
Return Value
bool or custom result
Boolean for ordinary built-in comparisons; custom rich comparison methods can return other values.
Working Example
Example Snippetpython
print(3 <= 3)print((1,2) <= (1,3))print({1,2} <= {1,2})