Python中@property的粗略理解
来源:互联网 发布:js调用android的方法 编辑:程序博客网 时间:2024/06/10 09:57
代码:
# -*- coding:utf-8 -*-#!/usr/bin/env pythonclass Student(object):
@property def get_score(self): return self._score @get_score.setter def set_score(self, value): if not isinstance(value, int): raise ValueError('score must be an integer!') if value < 0 or value > 100: raise ValueError('score must between 0 ~ 100!') self._score = value
s=Student()s.set_score=60print s.get_score
@property
装饰器把get_score方法变成属性调用
而在set_score方法上加上@get_score.setter意思是get_score方法中的属性是通过set_score来设置的
0 0
- Python中@property的粗略理解
- python中property函数的理解
- Python中property属性(特性)的理解
- 对于Python中@property的理解和使用
- m的粗略理解----gabu
- 对AbstractQueuedSychronizer的粗略理解
- python中@property的使用
- python @property理解
- linux下request_mem_region的粗略理解
- linux下request_mem_region的粗略理解
- linux下request_mem_region的粗略理解
- linux下request_mem_region的粗略理解
- 关于java反射机制的粗略理解
- Python中Property内建函数深入理解
- 【c++基础】关于继承关系中构造函数的粗略理解
- python中@property装饰器的用法
- python中@property与Descriptor的使用方法
- 关于python中@property的使用
- matlab中的sort函数
- 19. Remove Nth Node From End of List
- Spark算子篇-combineByKey实战
- FragmentTabHost的使用--仿微信首页搭建
- 关于一道简单的Java 基础面试题的剖析: short s1=1;s1 = s1 +1会报错吗?
- Python中@property的粗略理解
- 阿里面试题总结
- 【天梯赛-练习题】L2-007 家庭房产
- Objective C类方法load和initialize的区别
- 使用jutil测试程序出现错误java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=classestest]
- 几种排序
- 开平方算法
- 第一次
- 8、覆盖equas时请遵守约定