Built-in Functions and Types
property()
Create a managed attribute descriptor. Reading, assigning or deleting the attribute invokes the corresponding accessor when supplied. A missing accessor raises AttributeError for that operation. The getter decorator and getter(), setter() and deleter() methods let you construct accessor variants; these methods return a new property. A read-only property does not imply the returned value or entire instance is immutable.
Formal Syntax & Structure
python syntaxpython
property(fget=None, fset=None, fdel=None, doc=None)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| fget | callable or None | Getter receiving the instance. |
| fset | callable or None | Setter receiving instance and new value. |
| fdel | callable or None | Deleter receiving the instance. |
| doc | str or None | Documentation; defaults to getter docstring when available. |
Return Value
property
Data descriptor installed as a class attribute.
Working Example
Example Snippetpython
class Temperature: def __init__(self, celsius): self.celsius = celsius
@property def fahrenheit(self): return self.celsius * 9 / 5 + 32
print(Temperature(20).fahrenheit)