The property Function : property « Class « Python Tutorial






class Rectangle(object):
    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.width = 10
r.height = 5
print r.size
r.size = 150, 100
print r.width








11.3.property
11.3.1.The property Function
11.3.2.Objects in the class namespace can be accessed directly using the module name and dot . syntax.
11.3.3.An example of using a class data attribute (foo):
11.3.4.Demonstrates get and set methods and properties
11.3.5.Python properties (or attributes) are dynamic.
11.3.6.Define and access Properties