Discuss / Python / 坚持学

坚持学

Topic source
  1 #!/usr/bin/evn python3
  2 class Screen(object):
  3     @property
  4     def width(self):
  5         return self._width
  6     @width.setter
  7     def width(self, value):
  8         self._width = value
  9     @property
 10     def height(self):
 11         return self._heigth
 12     @height.setter
 13     def height(self, value):
 14         self._heigth = value
 15     @property
 16     def resolution(self):
 17         return self._width * self._heigth
 18 s = Screen()
 19 s.width = 1024
 20 s.height = 768
 21 print (s.resolution)
 22 assert s.resolution == 786432, '1024 * 768 = %d ?' % s.resolution

  • 1

Reply