Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
@property turns methods into attribute-style access with optional setter and deleter; it is built on descriptors, objects with __get__, __set__ or __delete__ that control attribute access when stored on a class.
With @property you can start with a plain attribute and later add validation or computed values without changing callers, since obj.price still reads like an attribute. Under the hood, property is a descriptor: when Python looks up an attribute on an instance and finds an object on the class that defines get, it calls that method instead of returning the object. Data descriptors, which define set, take priority over the instance dictionary. Functions themselves are descriptors, which is how methods become bound to instances. Custom descriptors are useful for reusable field logic, such as typed or validated fields in ORMs.