-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuse_property.py
More file actions
48 lines (36 loc) · 915 Bytes
/
Copy pathuse_property.py
File metadata and controls
48 lines (36 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class Student(object):
@property
def score(self):
return self._score
@score.setter
def 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 be between 0~100")
self._score=value
s=Student()
s.score=60
print("s.score = ", s.score)
s.score=99
class Screen(object):
@property
def width(self):
return self._width
@width.setter
def width(self,value):
self._width=value
@property
def height(self):
return self._height
@height.setter
def height(self,value):
self._height=value
@property
def resolution(self):
return self._width * self._height
s=Screen()
s.width=1024
s.height=768
print(s.resolution)
assert s.resolution==786432, "1024*768 = %d ?" % s.resolution