[python]请利用@property给一个Screen对象加上width和height属性,以及一个只读属性resolution:

# -*- coding: utf-8 -*-
class Screen(object):
    @property   #相当于定义get_width方法
    def width(self):
        return self._width

    @width.setter   #相当于定义set_width方法
    def width(self,value):
        self._width = value

    @property    #相当于定义get_height方法
    def height(self):
        return self._height

    @height.setter    #相当于定义set_height方法
    def height(self,value):
        self._height = value

    @property    #定义只读参数
    def resolution(self):
        return self.width * self._height
原文地址:https://www.cnblogs.com/cccmon/p/7976467.html