We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e862016 commit 0f78debCopy full SHA for 0f78deb
1 file changed
property.py
@@ -1,13 +1,19 @@
1
-__author__ = 'tanteng'
2
-
3
-class Ver(object):
4
- def __init__(self,version):
5
- self.version = version
+# -*- coding: utf-8 -*-
6
+# 属性装饰器
+class Student(object):
7
@property
8
- def version_no(self):
9
- return self.version
+ def score(self):
+ return self._score
10
+ @score.setter
+ def score(self, value):
11
+ if not isinstance(value,int):
12
+ raise ValueError('必须输入数字!')
13
+ if value<0 or value>100:
14
+ raise ValueError('必须大于0小于100!')
15
+ self._score = value
16
-ver = Ver('2.0')
-print(ver.version_no)
17
+s = Student()
18
+s.score = 101
19
+print(s.score)
0 commit comments