> Greater than
Last updated: 2026-09-22
> Greater than
> tests a > b (via __gt__).
| Category | Operators |
|---|---|
| Kind | Operator |
| Python Version | all |
📝 Syntax
a > b
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
True
True
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QIs the notation 5 > 3 > 1 valid?
AYes. Python supports chained comparisons; it is equivalent to `5 > 3 and 3 > 1`, and the middle `3` is evaluated only once.
QHow does a custom class support the > operator?
AImplement the `__gt__` method. If you only implement `__lt__`, you can pair it with the `functools.total_ordering` decorator to auto-fill the other comparison operators.
QHow is the string 'b' > 'a' compared?
ABy Unicode code points, one character at a time: the code point 98 of `'b'` is greater than 97 of `'a'`, so it is `True`. Chinese characters work the same way — code points, not pinyin.