Programming Languages Python Subjective
Sep 30, 2025

How do you implement a simple class with getter and setter properties?

Detailed Explanation
class Person:\n def __init__(self):\n self._age = 0\n \n @property\n def age(self):\n return self._age\n \n @age.setter\n def age(self, value):\n if value < 0:\n raise ValueError("Age cannot be negative")\n self._age = value
Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback