python @property和@attribute.setter理解

python @property和@attribute.setter理解

 

 

```python

class Human:

def __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')

h1 = Human('sai',22)
print(h1.age)
h1.age += 5
print(h1.age)

上一篇:java.lang.IllegalStateException:Type handler was null on parameter mapping for property ‘__frch_list


下一篇:Sagit.Framework For IOS 自动布局教程:14、UIScrollView :分页、分页组件呈现、分页事件、设置分页大小、批量加载图片呈现。