<

Strict ordering — with chaining: lo < x < hi reads exactly as written.

Comparison operatorPython 1.0+Live demo
Common call
if age < 18:
Returns
bool
Replaces
chains: 0 < x < 10 means 0 < x and x < 10
Watch out
int < str raises TypeError (Python 3 change)
aa — Left operand.type: comparable · required < bb — Right operand — must be orderable against a.type: comparable · required
→ bool

Demo

Live evaluation
Try:
Inputs
afloatleft
bfloatright
Output
3 < 5
True

Strictly less — equal operands give False. Strings order lexicographically and sequences element-by-element in real Python; numbers here.

Operands

NameTypeRequiredDescription
acomparableyesLeft operand.
bcomparableyesRight operand — must be orderable against a.

Return value

bool — True when a orders strictly before b. Unrelated types raise TypeError in Python 3.

Common patterns

Chained range checks
Python evaluates chains as AND of adjacent pairs.
if 0 <= index < len(items):
    return items[index]
Lexicographic sequence comparison
Tuples/lists compare element-by-element, first difference wins.
(1, "b") < (1, "c")   # True
[1, 2] < [1, 2, 0]     # True — shorter is less

Examples

1. Numbers
3 < 5
Returns
True
2. Chained
0 < 5 < 10
Returns
True
3. Strings — lexicographic
"apple" < "banana"
Returns
True
4. Mixed types raise
1 < "2"
Returns
TypeError: '<' not supported between instances of 'int' and 'str'

Pitfalls

1. Mixed types raise in Python 3
Python 2 silently ordered by type name — Python 3 refuses.
Raises
1 < "2"
TypeError: '<' not supported between instances of 'int' and 'str'
Convert first
1 < int("2")
True
2. Uppercase orders before lowercase
String ordering is by code point — "Z" < "a".
Surprising
"Zebra" < "apple"
True
Case-insensitive
"Zebra".lower() < "apple".lower()
False
3. Chaining evaluates each operand once — but reads as pairs
a < b < c is NOT (a < b) < c.
C-style reading
(0 < 5) < 3   # True < 3 → 1 < 3
True — nonsense comparison
Python chains
0 < 5 < 3
False — as intended

When to use

Use it
  • Ordering checks; chained ranges (lo <= x < hi)
  • Sorting-related predicates
Reach for something else
  • Mixed types → normalize first
  • Case-insensitive string order → compare .lower()/casefold()

Notes

Complexity
O(1) numbers; O(n) sequences
Return
bool
CPython impl
Objects/object.c :: PyObject_RichCompare (Py_LT) → __lt__
Memory
No allocation
Thread-safe
Yes for immutable operands

FAQ

sorted() and list.sort() use __lt__ exclusively — implement it (plus functools.total_ordering for the rest) to make a class sortable.

History

3.0
Cross-type ordering (1 < "2") now raises instead of ordering by type name.