class Circle:
def __init__(self, radius):
self._radius = radius
@property
def radius(self):
print("Getting radius")
return self._radius
@radius.setter
def radius(self, value):
print("Setting radius")
if value >= 0:
self._radius = value
else:
raise ValueError("Radius cannot be negative.")
@radius.deleter
def radius(self):
print("Deleting radius")
del self._radius
# Creating an instance of the Circle class
circle = Circle(5)
# Accessing the radius property (getter is called)
print(circle.radius)
# Output: Getting radius
# 5
# Setting the radius property (setter is called)
circle.radius = 7
# Output: Setting radius
# Trying to set a negative radius (setter raises an exception)
circle.radius = -3
# Output: Setting radius
# ValueError: Radius cannot be negative.
# Deleting the radius property (deleter is called)
del circle.radius
# Output: Deleting radius