__ge__Easy Examples

Defines behavior for the >= operator

Implementing __ge__

Basic implementation of __ge__ in a class.

python
class Example:
    def __ge__(self):
        return "Example __ge__"

obj = Example()
print(obj)

__ge__ defines behavior for the >= operator. Implementing it lets you customize how Python interacts with your objects.

__ge__ in action

Seeing __ge__ called by Python's built-in operations.

python
# How Python calls __ge__ automatically
class Demo:
    def __init__(self, value):
        self.value = value

    def __ge__(self, other):
        print(f"__ge__ was called!")
        return self

d = Demo(42)
# This triggers __ge__:
print(d)

Python automatically calls __ge__ when you use the corresponding operator or function on your object.

Want to try these examples interactively?

Open Easy Playground