[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

 

posted on 2017-12-04 12:03  cccmon  阅读(928)  评论(0编辑  收藏  举报

导航