python学习之property进阶
#第一种方式:
# class Foo:
# @property
# def AAA(self):
# print("get")
#
# @AAA.setter
# def AAA(self,value):
# print('set',value)
#
# @AAA.deleter
# def AAA(self):
# print('delete')
#第二种方式:
class Foo:
def get_AAA(self):
print('get')
def set_AAA(self,value):
print('set',value)
def delete_AAA(self):
print('delete')
AAA=property(get_AAA,set_AAA,delete_AAA) #内置property三个参数与get,set,delete一一对应
#只有在属性AAA定义property后才能定义AAA.setter,AAA.deleter
f1=Foo()
f1.AAA
f1.AAA=12