Python标准库:内置函数property(fget=None, fset=None, fdel=None, doc=None)
2015-03-11 08:22
253 查看
本函数是设置类成员的属性。参数fget是获取类成员的属性值;参数fset是设置类成员的属性值;fdel是删除类成员;参数doc是设置属性的文档字符串。通过这个函数的方式,可以实现类成员变量隐藏的方式,也就是面向对象里封装的要求。
例子:
结果输出如下:
2000
蔡军生 QQ:9073204 深圳
例子:
#property() class Foo: def __init__(self): self._x = None def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I'm the 'x' property.") foo = Foo() foo.x = 2000 print(foo.x) del foo.x
结果输出如下:
2000
蔡军生 QQ:9073204 深圳
相关文章推荐
- Python标准库:内置函数property(fget=None, fset=None, fdel=None, doc=None)
- Python 内建函数 - property(fget=None, fset=None, fdel=None, doc=None)
- Python标准库:内置函数open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=T
- Python标准库:内置函数eval(expression, globals=None, locals=None)
- Python标准库:内置函数__import__(name, globals=None, locals=None, fromlist=(), level=0)
- python笔记13 - 系统模块,自定义模块的编写,模块的搜索路径,PYTHONPATH环境变量,模块的属性:__doc__, __all__,__file__,标准库模块,包
- Python标准库:内置函数open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=T
- Python标准库:内置函数eval(expression, globals=None, locals=None)
- Python标准库:内置函数eval(expression, globals=None, locals=None)
- Python标准库:内置函数__import__(name, globals=None, locals=None, fromlist=(), level=0)
- Python 标准库 urllib2 的使用细节
- Python标准库-random模块
- Python标准库
- Python标准库的强大功能的相关介绍
- python标准库学习3
- Python标准库-traceback模块
- Python 标准库 urllib2 的使用细节
- Python 2.7 Tutorial —— 标准库
- python中的文档字符串(docString)
- Python 标准库 urllib2 的使用细节