python property

class Rectangle:
    def __init__(self):
        self.width = 0
        self.height = 0

    def setSize(self, size):
        self.width, self.height = size

    def getSize(self):
        return self.width,self.height

    size = property(getSize,setSize)

r = Rectangle()

r.size = 10, 15
print(r.size)

result :

 

(10, 15)

  

posted @ 2019-06-25 13:17  嵌入式实操  阅读(92)  评论(0编辑  收藏  举报