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