> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Python Less Than

The `<` (less than) operator is a strict relational operator that evaluates whether the left operand is strictly smaller in mathematical value, precedes in lexicographical order, or is a strict proper subset of the right operand. It evaluates the expression and returns a boolean value (`True` or `False`).

```python theme={"dark"}
operand_a < operand_b
```

## Underlying Implementation

When the `<` operator is invoked, Python internally delegates the operation to the `__lt__()` special (dunder) method of the left operand.

However, Python's data model enforces a specific method resolution order regarding operator overloading and subclasses. If the right operand is an instance of a strict subclass of the left operand's type, Python prioritizes the subclass. It will call the right operand's `__gt__()` (greater than) method *before* attempting to call the left operand's `__lt__()` method.

```python theme={"dark"}

# Standard method resolution for a < b
a.__lt__(b)


# Resolution if type(b) is a strict subclass of type(a)
b.__gt__(a)
```

If the initially called method does not support the type of the other operand, it returns the `NotImplemented` singleton. Python's interpreter then falls back to calling the reflected method on the other operand (e.g., falling back to `b.__gt__(a)` if `a.__lt__(b)` returns `NotImplemented`). If both methods return `NotImplemented`, a `TypeError` is raised.

## Evaluation Mechanics by Data Type

The behavior of the `<` operator is strictly defined by the data types of the operands:

* **Numeric Types (`int`, `float`, `Decimal`, `Fraction`):** Evaluates the exact mathematical value. Python compares mixed numeric types (such as an `int` and a `float`) by evaluating their exact mathematical values to avoid precision loss. It does *not* coerce them to a common type (which could result in precision loss for very large integers). While most cross-type numeric comparisons are natively handled, comparing a `Decimal` to a `Fraction` is not supported and will raise a `TypeError`.
* **Strings (`str`):** Performs a strict lexicographical comparison based on the Unicode code point values of the characters. Python compares the strings character by character from left to right using the integer values returned by the `ord()` function.
* **Sequences (`list`, `tuple`):** Evaluates elements lexicographically, item by item, starting from index `0`. The comparison terminates at the first unequal pair of elements. If all evaluated elements are equal but one sequence is shorter, the shorter sequence is evaluated as strictly less than the longer sequence.
* **Sets (`set`, `frozenset`):** Evaluates as a strict proper subset test. The expression `a < b` returns `True` only if all elements of `a` exist in `b`, and `b` contains at least one element not present in `a` (i.e., `a` is a subset of `b`, but `a != b`).

## Operator Chaining

Python allows the `<` operator to be chained with other relational operators. The interpreter evaluates chained comparisons using implicit logical `AND` operations with short-circuit evaluation semantics.

```python theme={"dark"}

# Chained syntax
a < b < c


# Logically equivalent (but operationally different)
(a < b) and (b < c)
```

In the chained evaluation `a < b < c`, the middle operand `b` is evaluated exactly once. This is operationally distinct from the explicit `and` expression, which evaluates `b` twice if `a < b` is `True`. In both cases, if `a < b` evaluates to `False`, the `b < c` expression is never evaluated due to short-circuiting.

## Type Compatibility

Unlike some dynamically typed languages, Python is strongly typed regarding comparisons. If the operands are of incompatible types (e.g., an `int` and a `str`), the `<` operator will not perform implicit type coercion.

```python theme={"dark"}

# This will raise a TypeError: '<' not supported between instances of 'int' and 'str'
5 < "10"
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Python Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
