面向对象使用装饰器进行修饰(python)

学习内容来源:廖雪峰面向对象Python3

# coding:gbk

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 "像素点:%d * %d = %d" % (self._width,self._height,self._width*self._height)
        
f = Screen()
f.width = 1024
f.height = 768

print(f.resolution)
原文地址:https://www.cnblogs.com/loyfee/p/5807653.html