property() Property descriptor
Last updated: 2026-09-22
property() Property descriptor
property(fget, fset, fdel, doc) wraps accessors into an attribute-like object; also available via @property.
| Category | Built-in Functions |
|---|---|
| Kind | Built-in Function |
| Python Version | all |
📝 Syntax
property(fget[, fset[, fdel[, doc]]])
⚙️ Parameters
| fget Optional | Function for getting the attribute value (getter).(Default:None) |
|---|---|
| fset Optional | Function for setting the attribute value (setter).(Default:None) |
| fdel Optional | Function for deleting the attribute (deleter).(Default:None) |
| doc Optional | Docstring for the property.(Default:None) |
Returns:A property object, a data descriptor accessed like a normal attribute.
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
10
🏷️ Related Built-in Functions
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat is property for?
AIt wraps a method as attribute access: obj.x triggers the getter logic without parentheses, and you can add validation on assignment (via a setter), enabling computed attributes and encapsulation.
QHow do @property and @x.setter work together?
A@property defines the read logic and @x.setter the assignment validation, e.g. c.x = 10 goes through the setter; if only @property is defined without a setter, assigning raises AttributeError: can't set attribute.
QWhat is the difference between property and a plain method?
AThe access style differs (obj.x instead of obj.x()), and property can intercept the read, assign, and delete operations — suited to encapsulating and validating internal fields.
QDoes a computed property cache its result?
ANo, accessing obj.x re-runs the getter each time; to cache it you must implement it yourself (e.g. functools.cached_property).