类的属性
1 class provence: 2 # 构造函数 3 def __init__(self, name): 4 self.name = name 5 # 特性,将方法伪造成字段 6 @property 7 def end(self): 8 temp = '%s sb' % self.name 9 return temp 10 # 设置end的返回值 11 @end.setter 12 def end(self,value): 13 print(value) 14 self.name = value 15 16 r = provence('hhh') 17 print(r.end) 18 r.end = '123' # 传递参数修改end的返回值 19 print(r.end)
hhh sb
123
123 sb