python @property和@attribute.setter理解
2021-05-30 18:04
标签:python prope code sel mamicode lazy ini class loading class Human: h1 = Human(‘sai‘,22) python @property和@attribute.setter理解 标签:python prope code sel mamicode lazy ini class loading 原文地址:https://www.cnblogs.com/xiaozhusai/p/14747722.htmldef __init__(self, name, age):
self.__name = name
self.__age = age
@property
def age(self):
return self.__age
@age.setter
def age(self, age):
if age > 0:
self.__age = age
else:
print(‘error‘)
print(h1.age)
h1.age += 5
print(h1.age)
文章标题:python @property和@attribute.setter理解
文章链接:http://soscw.com/index.php/essay/89649.html