Discuss / Python / Answers from Maplin on 2022-12-26

Answers from Maplin on 2022-12-26

Topic source

>>> 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('resolution =', s.resolution)

resolution = 786432

>>> if s.resolution == 786432:

...     print('测试通过!')

... else:

...     print('测试失败!')

...

测试通过!

>>>


  • 1

Reply