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.

CategoryBuilt-in Functions
KindBuilt-in Function
Python Versionall

📝 Syntax

property(fget[, fset[, fdel[, doc]]])

⚙️ Parameters

fget OptionalFunction for getting the attribute value (getter).(Default:None)
fset OptionalFunction for setting the attribute value (setter).(Default:None)
fdel OptionalFunction for deleting the attribute (deleter).(Default:None)
doc OptionalDocstring 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
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).
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏