Python学习笔记——Property用法
来源:互联网 发布:教课程财务会计软件 编辑:程序博客网 时间:2024/06/05 17:32
property使用方法有两种,写好以后发挥的作用是相同的。
写法一
class Test(object): """docstring for Test""" def __init__(self): super(Test, self).__init__() self.__num = 10 def getNum(self): return self.__num def setNum(self,newNum): self.__num = newNum num = property(getNum,setNum)
写法二(装饰器)
class Test(object): """docstring for Test""" def __init__(self): super(Test, self).__init__() self.__num = 100 @property def num(self): return self.__num @num.setter def num(self,newNum): self.__num = newNum
两种方法运行结果都一样。只不过用法不同而已。
说白了就是懒,就是为了直接使用 t.num 这种方法操作私有属性。
阅读全文
0 0
- Python学习笔记——Property用法
- python学习笔记 - @property
- python学习笔记 - @property
- python学习笔记 - @property
- Python 学习笔记property
- python学习笔记 使用@property
- python学习——使用@property
- 【Python】学习笔记——-8.2、面向对象高级编程:2.使用@property
- python Property属性用法
- python Property属性用法
- python Property属性用法
- python property 函数用法
- python Property属性用法
- Python 中 property 用法
- python property的用法
- Python之 @property 用法
- Python @property 的用法
- Objective-C学习——@property和@synthesize用法
- 1044. Shopping in Mars (25)
- 153. Find Minimum in Rotated Sorted Array--在旋转数组中找最小值
- Android学习之使用seekbar进行歌曲的同步
- gitlab一键安装
- 简单的CSS动画加JS实现转盘
- Python学习笔记——Property用法
- STP个人理解
- HttpsURLConnection发送get型式参数
- Android App整体架构设计的思考
- 题目1448:Legal or Not
- 关于显示隐藏的小技巧
- 1000行代码手写HTTP服务器
- 解析并且存入数据库
- 使用js进行时间戳与日期的相互转化