class Screen(object):
@property
def width(self):
return self._width
@width.setter
def width(self,value):
if isinstance(value,int) and value>0:
self._width=value
else:
print('width is illegal')
@property
def height(self):
return self._height
@height.setter
def height(self,value):
if isinstance(value,int) and value>0:
self._height=value
else:
print('height is illagal')
@property
def resolution(self):
if hasattr(self,'width') and hasattr(self,'height'):
return self._width * self._height
else:
print('please define all attributes')
_Indescribable
#!/usr/bin/env python3
-- coding: utf-8 --
class Screen(object): @property def width(self): return self._width
s=Screen() s.width=1024 s.height=768 print(s.resolution)