class Student(object): def __init__(self,value,value1): self.value= value self.value1 = value1 @property def birth(self): return self._birth @birth.setter def birth(self, value): self._birth = value # @property # def age(self): @property def age(self): return self.value1- self._birth a = Student(1995,2010) a.birth = 2000 print(a.age)
python_类_只读属性设置年龄,读写属性设置出生日期
最新推荐文章于 2022-03-09 09:29:43 发布