The property() function returns a special descriptor object:

>>> property()
<property object at 0x10ff07940>

It is this object that has extra methods:

>>> property().getter
<built-in method getter of property object at 0x10ff07998>
>>> property().setter
<built-in method setter of property object at 0x10ff07940>
>>> property().deleter
<built-in method deleter of property object at 0x10ff07998>

These act as decorators too. They return a new property object:

>>> property().getter(None)
<property object at 0x10ff079f0>

that is a copy of the old object, but with one of the functions replaced.

Remember, that the @decorator syntax is just syntactic sugar; the syntax:

@property
def foo(self): return self._foo

really means the same thing as

def foo(self): return self._foo
foo = property(foo)

so foo the function is replaced by property(foo), which we saw above is a special object. Then when you use @foo.setter(), what you are doing is call that property().setter method I showed you above, which returns a new copy of the property, but this time with the setter function replaced with the decorated method.

The following sequence also creates a full-on property, by using those decorator methods.

First we create some functions:

>>> def getter(self): print('Get!')
... 
>>> def setter(self, value): print('Set to {!r}!'.format(value))
... 
>>> def deleter(self): print('Delete!')
... 

Then, we create a property object with only a getter:

>>> prop = property(getter)
>>> prop.fget is getter
True
>>> prop.fset is None
True
>>> prop.fdel is None
True

Next we use the .setter() method to add a setter:

>>> prop = prop.setter(setter)
>>> prop.fget is getter
True
>>> prop.fset is setter
True
>>> prop.fdel is None
True

Last we add a deleter with the .deleter() method:

>>> prop = prop.deleter(deleter)
>>> prop.fget is getter
True
>>> prop.fset is setter
True
>>> prop.fdel is deleter
True

Last but not least, the property object acts as a descriptor object, so it has .__get__(), .__set__() and .__delete__() methods to hook into instance attribute getting, setting and deleting:

>>> class Foo: pass
... 
>>> prop.__get__(Foo(), Foo)
Get!
>>> prop.__set__(Foo(), 'bar')
Set to 'bar'!
>>> prop.__delete__(Foo())
Delete!

The Descriptor Howto includes a pure Python sample implementation of the property() type:

class Property:
    "Emulate PyProperty_Type() in Objects/descrobject.c"

    def __init__(self, fget=None, fset=None, fdel=None, doc=None):
        self.fget = fget
        self.fset = fset
        self.fdel = fdel
        if doc is None and fget is not None:
            doc = fget.__doc__
        self.__doc__ = doc

    def __get__(self, obj, objtype=None):
        if obj is None:
            return self
        if self.fget is None:
            raise AttributeError("unreadable attribute")
        return self.fget(obj)

    def __set__(self, obj, value):
        if self.fset is None:
            raise AttributeError("can't set attribute")
        self.fset(obj, value)

    def __delete__(self, obj):
        if self.fdel is None:
            raise AttributeError("can't delete attribute")
        self.fdel(obj)

    def getter(self, fget):
        return type(self)(fget, self.fset, self.fdel, self.__doc__)

    def setter(self, fset):
        return type(self)(self.fget, fset, self.fdel, self.__doc__)

    def deleter(self, fdel):
        return type(self)(self.fget, self.fset, fdel, self.__doc__)
Answer from Martijn Pieters on Stack Overflow
Top answer
1 of 15
1350

The property() function returns a special descriptor object:

>>> property()
<property object at 0x10ff07940>

It is this object that has extra methods:

>>> property().getter
<built-in method getter of property object at 0x10ff07998>
>>> property().setter
<built-in method setter of property object at 0x10ff07940>
>>> property().deleter
<built-in method deleter of property object at 0x10ff07998>

These act as decorators too. They return a new property object:

>>> property().getter(None)
<property object at 0x10ff079f0>

that is a copy of the old object, but with one of the functions replaced.

Remember, that the @decorator syntax is just syntactic sugar; the syntax:

@property
def foo(self): return self._foo

really means the same thing as

def foo(self): return self._foo
foo = property(foo)

so foo the function is replaced by property(foo), which we saw above is a special object. Then when you use @foo.setter(), what you are doing is call that property().setter method I showed you above, which returns a new copy of the property, but this time with the setter function replaced with the decorated method.

The following sequence also creates a full-on property, by using those decorator methods.

First we create some functions:

>>> def getter(self): print('Get!')
... 
>>> def setter(self, value): print('Set to {!r}!'.format(value))
... 
>>> def deleter(self): print('Delete!')
... 

Then, we create a property object with only a getter:

>>> prop = property(getter)
>>> prop.fget is getter
True
>>> prop.fset is None
True
>>> prop.fdel is None
True

Next we use the .setter() method to add a setter:

>>> prop = prop.setter(setter)
>>> prop.fget is getter
True
>>> prop.fset is setter
True
>>> prop.fdel is None
True

Last we add a deleter with the .deleter() method:

>>> prop = prop.deleter(deleter)
>>> prop.fget is getter
True
>>> prop.fset is setter
True
>>> prop.fdel is deleter
True

Last but not least, the property object acts as a descriptor object, so it has .__get__(), .__set__() and .__delete__() methods to hook into instance attribute getting, setting and deleting:

>>> class Foo: pass
... 
>>> prop.__get__(Foo(), Foo)
Get!
>>> prop.__set__(Foo(), 'bar')
Set to 'bar'!
>>> prop.__delete__(Foo())
Delete!

The Descriptor Howto includes a pure Python sample implementation of the property() type:

class Property:
    "Emulate PyProperty_Type() in Objects/descrobject.c"

    def __init__(self, fget=None, fset=None, fdel=None, doc=None):
        self.fget = fget
        self.fset = fset
        self.fdel = fdel
        if doc is None and fget is not None:
            doc = fget.__doc__
        self.__doc__ = doc

    def __get__(self, obj, objtype=None):
        if obj is None:
            return self
        if self.fget is None:
            raise AttributeError("unreadable attribute")
        return self.fget(obj)

    def __set__(self, obj, value):
        if self.fset is None:
            raise AttributeError("can't set attribute")
        self.fset(obj, value)

    def __delete__(self, obj):
        if self.fdel is None:
            raise AttributeError("can't delete attribute")
        self.fdel(obj)

    def getter(self, fget):
        return type(self)(fget, self.fset, self.fdel, self.__doc__)

    def setter(self, fset):
        return type(self)(self.fget, fset, self.fdel, self.__doc__)

    def deleter(self, fdel):
        return type(self)(self.fget, self.fset, fdel, self.__doc__)
2 of 15
403

The documentation says it's just a shortcut for creating read-only properties. So

@property
def x(self):
    return self._x

is equivalent to

def getx(self):
    return self._x
x = property(getx)
🌐
Programiz
programiz.com › python-programming › property
Python @property Decorator (With Examples)
Let's look at how to implement this as a decorator: class Celsius: def __init__(self, temperature=0): # when creating the object, the setter method is called automatically self.temperature = temperature def to_fahrenheit(self): # convert the temperature to Fahrenheit return (self.temperature ...
Discussions

Use of "@property" decorator

They are functionally equivalent, yes.

First, consider what happens without the decorator. An object has properties, which can be either attributes or functions. If you remove the @property decorator from your class definition and change the line above that to self.foo = 10, then the line a = A() creates a new object that has two attributes: a.foo and a.value. Now, a.foo is an int, which is a static sort of object. For one thing, you can't call it. a.foo() would be a syntax error. a.value, on the other hand, is a function, and so a.value() does make sense, and what python does is finds the function named a.value, runs it, and returns the value.

Now, when you add a @property decorator, it makes python think that a.value is actually an attribute property, not a function property. All that really changes is the syntax. Now you don't have to call a.value(), you just reference a.value as though it were some static sort of value. Why would you want to do this? Well, imagine that you are working with a number of classes, and it makes sense for all of them to have some similar property. For example, say you are making a phone directory of professors that will return the current phone number when requested. Usually it's fine for you to just reference prof.number, since it stays the same. But say you want to add a new person who spends half their time in Australia and half in Arizona. You could completely re-write the professor class to change the sort of thing that prof.number is, and let it look up the number when needed. If you already have a lot of code, though, that can be problematic, since you need to go through and change everything. So an alternative is to create a new subclass of professor that has a @property that will do some sort of calculation to determine the correct number at this time of year. Now everywhere that you referenced prof.number will still work just as before, but you can still do that sort of calculation.

To close: a word of warning. Keep in mind that using the @property decorator still means that you're repeatedly calling a function. It's easy to forget this, and you end up referencing prof.number a lot, and if the calculation takes a long time, then you're re-doing it every time. This can get to be a big waste of time.

More on reddit.com
🌐 r/learnpython
7
4
May 8, 2012
class property decorators

Why do you want to do this? Having short aliases for longer things is good when you're designing a user interface, but in a class you typically want to have a single source of truth. These aliases make your code significantly more complex so that you can save a little bit of typing elsewhere.

More on reddit.com
🌐 r/learnpython
10
11
December 22, 2018
Equivalent of Python's @property decorator for interdependent attributes
Hi All- While home for the holidays I wanted to undertake a project, using the Processing language (Java flavor). I'm creating an object that… More on reddit.com
🌐 r/javahelp
2
5
December 22, 2015
@property decorators

It isn't that bad, the major thing that I would change is to work with a single storage unit, preferably Kelvin. Then for the setters you don't need to use the minima values but simply check if the conversion result is >= 0. I would also employ a library like pytemperature to perform the conversions as it cleans op the code a lot: you simply need two setters and two properties and not other methods. And you don't run the risk of making a calculation mistake of course.

More on reddit.com
🌐 r/learnpython
5
1
February 13, 2019
🌐
Python Basics
python-basics-tutorial.readthedocs.io › en › latest › oop › property.html
@property decorator - Python Basics
1 month ago - Note that the name of the method remains the same, but the decorator changes to the property name, in our case to length.setter: >>> s1 = form.Square() >>> s1.length = 2 >>> s1.perimeter() 8 · A big advantage of Python’s ability to add properties is that you can work with plain old instance variables at the beginning of development and then seamlessly switch to property variables whenever and wherever you need to, without changing the client code.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-property-decorator-property
Python Property Decorator - @property - GeeksforGeeks
July 12, 2025 - Example 2: ... # Python program to illustrate the use of # @property decorator # Creating class class Celsius: # Defining init method with its parameter def __init__(self, temp = 0): self._temperature = temp # @property decorator @property # Getter method def temp(self): # Prints the assigned temperature value print("The value of the temperature is: ") return self._temperature # Setter method @temp.setter def temp(self, val): # If temperature is less than -273 than a value # error is thrown if val < -273: raise ValueError("It is a value error.") # Prints this if the value of the temperature is
🌐
Tutorial Teacher
tutorialsteacher.com › python › property-decorator
Python: Property Decorator @property
You can use the following three decorators to define a property: ... @<property-name>.setter: Specifies the setter method for a property that sets the value to a property. @<property-name>.deleter: Specifies the delete method as a property that ...
🌐
StrataScratch
stratascratch.com › blog › how-to-use-python-property-decorator-with-examples
How to Use Python Property Decorator (With Examples) - StrataScratch
November 16, 2023 - Used the Python property decorator for undergoing_treatment to get the status. Employed @undergoing_treatment.deleter to specify the conditions under which the attribute can be deleted. In this example, the deletion is conditioned on whether the patient is undergoing treatment.
🌐
Python Tutorial
pythontutorial.net › home › python oop › python property decorator
Python Property Decorator
March 31, 2025 - Therefore, you can use the @property decorator to decorate the age() method as follows: class Person: def __init__(self, name, age): self.name = name self._age = age @property def age(self): return self._age Code language: Python (python)
Find elsewhere
🌐
freeCodeCamp
freecodecamp.org › news › python-property-decorator
The @property Decorator in Python: Its Use Cases, Advantages, and Syntax
December 19, 2019 - I know you may be asking: how is this related to the @property? The @property is a built-in decorator for the property() function in Python.
🌐
Real Python
realpython.com › python-property
Python's property(): Add Managed Attributes to Your Classes – Real Python
April 17, 2026 - Circle now is more Pythonic and clean. You don’t need to use method names such as ._get_radius(), ._set_radius(), and ._del_radius() anymore. Now you have three methods with the same descriptive attribute-like name. How’s that possible? The decorator approach for creating properties requires defining a first method using the public name for the underlying managed attribute, which is .radius in this example.
🌐
AskPython
askpython.com › python › built-in-methods › python-property-decorator
How to Use Python Property Decorator? - AskPython
June 21, 2021 - You can call this in your Python Interpreter and take a look: >>> property() <property object at 0x000002BBD7302BD8> This property object has some extra methods, for getting and setting the values of the object. It also has a method for deleting it. ... But it does not stop there! These methods can be used on other objects too, and act as decorators themselves! So, for example, we can use property().getter(obj), which will give us another property object!
🌐
LinkedIn
linkedin.com › pulse › understanding-property-decorator-python-nuno-bispo-m7aee
Understanding the @property Decorator in Python
February 7, 2024 - In this example, temperature acts as a property. Accessing c.temperature triggers the getter method, which simply returns the internal _temperature value, while setting c.temperature triggers the setter method, which includes a validation check. This encapsulates the internal representation (_temperature) and allows for additional logic (like validation) to be executed during attribute access. The @property decorator in Python makes implementing read-only attributes straightforward and elegant.
🌐
DEV Community
dev.to › amohgodwin › a-practical-guide-to-pythons-property-decorator-with-examples-26mo
A Practical Guide to Python's @property Decorator (with Examples) - DEV Community
July 13, 2025 - The property decorator also allows you to define a "setter" method, which is called whenever you assign a value to the property. This enables you to control how values are set. class ProgressReport: def __init__(self) -> None: self._progress = 19 @property def progress(self): return self._progress @progress.setter def progress(self, value): if 0 <= value <= 100: # More Pythonic range check self._progress = value else: raise ValueError("Progress must be a value between 0 and 100") # More specific exception reporter = ProgressReport() reporter.progress = 500 print(reporter.progress)
🌐
The Teclado Blog
blog.teclado.com › property-decorator-in-python
The @property decorator in Python - The Teclado Blog
May 12, 2022 - The property decorator allows us to define methods that act as attributes in Python classes. This simplifies using the objects, and extends what we can do when getting and setting attribute values.
🌐
FavTutor
favtutor.com › blogs › python-property-decorator
Python Property Decorator (with Examples)
November 6, 2023 - In this example, the fahrenheit property takes an argument for unit conversion, allowing you to work with Fahrenheit values while storing the temperature in Celsius. ... The first output shows the Fahrenheit temperature, and the second output ...
🌐
Stack Abuse
stackabuse.com › the-python-property-decorator
The Python Property Decorator
September 18, 2018 - In order to describe how the @property decorator works, let's take a look at a simpler decorator and how it works internally. A decorator is simply a function that takes another function as an argument and adding to its behavior by wrapping it. Here is a simple example: # decorator.py def some_func(): print 'Hey, you guys' def my_decorator(func): def inner(): print 'Before func!' func() print 'After func!' return inner print 'some_func():' some_func() print '' some_func_decorated = my_decorator(some_func) print 'some_func() with decorator:' some_func_decorated()
🌐
Medium
medium.com › @christopher.kelly1997 › python-decorators-and-dynamic-properties-55402a2e1aff
Python Decorators and Dynamic Properties | by Christopher Hugh Kelly | Medium
April 23, 2025 - Also the _ denotes a private attribute here in Python. That is also why you need the _ in the set too. So you don’t accidentally overwrite the property and cause access hell. We call the one with the _ in front of the name the private name. The one without is the public name. ... One other thing to note about the property method that you do not see here, technically the property decorator applies the access restrictions to a class attribute that is accessed via an object.
🌐
WsCube Tech
wscubetech.com › resources › python › property
Python Property: All Methods, Decorator & Examples
August 6, 2026 - Master Python property with examples. Learn how to use property() function, create properties, compare properties vs attributes, use property setters & more.
🌐
YouTube
youtube.com › andy dolinski
Property Decorators (OO Python Tutorials) - YouTube
Lesson 06 - Property decorators are a way of defining properties in a class, which are attributes that have some logic behind them. Properties allow you to a...
Published: November 26, 2023
Views: 153
🌐
Medium
medium.com › @dillonf2 › a-beginners-guide-to-python-s-property-decorator-ee01807cfdb1
A Beginner’s Guide to Python’s @property Decorator | by Frank Dillon | Medium
September 18, 2023 - In Python, @property is a built-in tool that helps you control how you access and modify attributes in a class. Think of it as a way to make your code neater and more straightforward. To understand this better, let's use an example.
🌐
CodeScracker
codescracker.com › python › python-property-decorator.htm
Python @property decorator
class CodesCracker: def __init__(self, val): self.v = val @property def val(self): print("\nGetting the Value") return self.v @val.setter def val(self, val): print("\nNow Setting the Value to \"", val, "\"", sep="") self.v = val @val.deleter def val(self): print("\nDeleting the Value") del self.v a = CodesCracker("Python is Fun!") print(a.val) a.val = "Python is an Object-oriented PL" print(a.val) del a.val · The sample output of the above program, demonstrating the @property decorator in Python, is shown in the snapshot given below: