From Python in a Nutshell
A property is an instance attribute with special functionality. ...
Here’s one way to define a read- only property:
class Rectangle(object): def __init__(self, width, height): self.width = width self.height = height def get_area(self): return self.width * self.height area = property(get_area, doc='area of the rectangle')Each instance r of class Rectangle has a synthetic read-only attribute r.area , computed on the fly in method r.get_area() by multiplying the sides.
Is a property a class attribute or an instance attribute?
Does the above quote imply that a property is an instance attribute?
A property is always defined inside the definition of a class, so is a property a class attribute.
Does
Rectangle.__dict__store the class attributes and anRectangleinstance's__dict__store the instance attributes? If yes, then does the following show that the property is a class attribute instead of an instance attribute:
>>> Rectangle.__dict__
mappingproxy({..., 'area': <property object at 0x7f34f7ee2818>})
>>> r=Rectangle(2,3)
>>> r.__dict__ {'width': 2, 'height': 3}
r.areaimplyareais an instance attribute of instancer?r.area, if it returns something, implies thatareais an attribute of the instance, or the class, or any of the classes in the MRO