标签:
类的属性
1.创建类的属性
class Pager: def __init__(self,all_count): self.all_count = all_count @property def all_pager(self): a1,a2 = divmod(self.all_count,10) if a2 == 0: return a1 else: return a1+1
2.获取类的属性
class Pager: def __init__(self,all_count): self.all_count = all_count @property def all_pager(self): a1,a2 = divmod(self.all_count,10) if a2 == 0: return a1 else: return a1+1 p = Pager(101) ret = p.all_pager print(ret)
out :
11
3、设置类的属性
使用装饰器 @all_pager.setter 然后使用 p.all_pager = 111 修改属性的值
class Pager: def __init__(self,all_count): self.all_count = all_count @property def all_pager(self): a1,a2 = divmod(self.all_count,10) if a2 == 0: return a1 else: return a1+1 @all_pager.setter def all_pager(self,value): print(value) p = Pager(101) p.all_pager = 111
out :
111
4、删除属性
使用@all_pager.deleter 和 del p.all_pager
class Pager: def __init__(self,all_count): self.all_count = all_count @property def all_pager(self): a1,a2 = divmod(self.all_count,10) if a2 == 0: return a1 else: return a1+1 @all_pager.deleter def all_pager(self): print(‘del all_pager‘) p = Pager(101) del p.all_pager
out:
del all_pager
标签:
原文地址:http://www.cnblogs.com/pangguoping/p/5617721.html