__get__ — Easy Examples
Descriptor protocol: called to get an attribute of the owner class
Implementing __get__
Basic implementation of __get__ in a class.
python
class Example: def __get__(self): return "Example __get__" obj = Example() print(obj)
__get__ descriptor protocol: called to get an attribute of the owner class. Implementing it lets you customize how Python interacts with your objects.
__get__ in action
Seeing __get__ called by Python's built-in operations.
python
# How Python calls __get__ automatically class Demo: def __init__(self, value): self.value = value def __get__(self): print(f"__get__ was called!") return self d = Demo(42) # This triggers __get__: print(d)
Python automatically calls __get__ when you use the corresponding operator or function on your object.
Want to try these examples interactively?
Open Easy Playground