from datetime import date, datetime class User:def __init__(self, name, birthday):self.name = nameself.birthday = birthdayself._age = 0# def get_age(self):# return datetime.now().year - self.birthday.year @property #动态属性def age(self): #属性描述符,get方法return datetime.now().year - self.birthday.year@age.setterdef age(self, value):self._age = valueif __name__ == "__main__":user = User("bobby", date(year=1987, month=1, day=1))user.age = 30print (user._age)print(user.age)