属性方法大家想必都用过
但是在进行代码封装的时候,大家应该用的都不少,
这里贴一段代码,算是记录一下对其进行赋值的过程
class Test():
@property
def name(self):
print('is running here 1')
return self.title
@name.setter
def name(self,value):
print('is running here 2')
self.title = value
t = Test()
t.name = '轰轰轰'
print(t.name)
结果:
is running here 2
is running here 1
轰轰轰
赋值的时候调用setter装饰的方法对属性方法赋值
print打印的值也与赋值结果相同
还有删除之类的,这里就不多说了