Use the @property decorator to define getter, setter, and deleter functions as properties of a class.
Source Code
class Circle:
def __init__(self, radius):
self._radius = radius
@property
def radius(self):
return self._radius
@radius.setter
def radius(self, value):
if value >= 0:
self._radius = value
else:
raise ValueError("Radius must be non-negative")