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

NameTypeDescription
fgetcallable or NoneGetter receiving the instance.
fsetcallable or NoneSetter receiving instance and new value.
fdelcallable or NoneDeleter receiving the instance.
docstr or NoneDocumentation; 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)
Python Reference