python 类属性
来源:互联网 发布:mac jmeter下载安装 编辑:程序博客网 时间:2024/05/01 20:25
__author__ = 'shijc'# 使用 @property 标识只读属性# 使用 @readonly_property.setter标识允许写入属性class People: def __init__(self, _name=__author__, _age=1): self._name = _name self._age = _age # 只读属性 @property def name(self): return self._name # 可写属性(只读的基础上实现) @name.setter def name(self, name): self._name = name @property def age(self): return self._agep = People()# 读写属性print(p.name) # shijcp.name += '-'print(p.name) # shijc-# 只读属性print(p.age)# p.age = 20 # 抛出异常:AttributeError: can't set attribute
0 0
- Python类属性,实例属性
- python类-属性
- Python 类属性介绍
- Python 类属性
- Python--类的属性
- python类:属性
- python 类属性
- python 类属性
- Python类的属性
- python类私有属性
- python 类属性
- Python类属性详解
- 类属性(1)-Python
- python内置类属性
- python-类的属性
- python 类属性
- Python 3.6 类属性
- python类的属性
- 三栏布局的实现
- 关于Node.js你必须要知道的原理性知识
- Flume:本地文件到HDFS
- Cordova(Phonegap)在iOS端App的使用(二)---插件的创建
- librbd代码目录解读
- python 类属性
- Leetcode题解 70. Climbing Stairs
- Android Studio 错误 Duplicate files copied in APK META-INF/LICENSE.txt
- 【Leetcode】1.Two Sum 解题
- 【码上杂谈】关于之前对Server上允许的最大TCP连接数理解错误的更正
- poj 2082 Terrible Sets
- 背包问题
- ZOJ-3802-Easy 2048 Again【状态压缩dp】【位运算】【好题】
- compoer安装