CKTIS / Python
object.__gt__
The method implements strict greater-than comparison and may decline with NotImplemented.
Version: Python 3.14; repository image, production runtime not attested
Syntax
left > rightThe method implements strict greater-than comparison and may decline with NotImplemented.
object.__gt__
The reflected counterpart is the right operand's __lt__. A strict right-hand subclass gets priority for reflected comparison. If neither side implements the comparison, the operator raises TypeError.
7 exceeds 3, equal scores fail >, and the string is unsupported.
events=[]
class A:
def __gt__(self,other): events.append('A'); return False
class B(A):
def __lt__(self,other): events.append('B'); return True
assert A()>B() and events==['B']
Examples
class Score:
def __init__(self, n): self.n=n
def __gt__(self, other):
if isinstance(other, Score): return self.n > other.n
return NotImplemented
print(Score(7) > Score(3), Score(3) > Score(3))
try: Score(1) > "1"
except TypeError as exc: print(type(exc).__name__)
Result
True False TypeError
7 exceeds 3, equal scores fail >, and the string is unsupported.