企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## 概述 property可写与可读 ```python #!/usr/bin/env python class Test1: def __init__(self): self.__private = 'alex' @property def show(self): return self.__private ``` 类test1没有继承object,特性show在类外部可读,可写 ``` t1 = Test1() print t1.show t1.Show = 'change 1' print t1.show ``` ```python class Test2(object): def __init__(self): self.__private = 'alex' @property def Show(self): return self.__private @Show.setter def Show(self, value): self.__private = value ``` 类test2继承object,特性show在类外部可读,默认不可写,需要通过设置setter变为可写 ```python t2 = Test2() print t2.show t2.show = 'change 2' print t2.show ```