1.@property实现只读变量 class Test(): def __init__(self, val): self.__val= val @property def onlyReadVal(self): return self.__val - 1 f = Test(2) print(f.onlyReadVal) 运行结果:2 如果添加: f.onlyReadVal = 3 会