Other examples would be validation/filtering of the set attributes (forcing them to be in bounds or acceptable) and lazy evaluation of complex or rapidly changing terms.

Complex calculation hidden behind an attribute:

class PDB_Calculator(object):
    ...
    @property
    def protein_folding_angle(self):
        # number crunching, remote server calls, etc
        # all results in an angle set in 'some_angle'
        # It could also reference a cache, remote or otherwise,
        # that holds the latest value for this angle
        return some_angle

>>> f = PDB_Calculator()
>>> angle = f.protein_folding_angle
>>> angle
44.33276

Validation:

class Pedometer(object)
    ...
    @property
    def stride_length(self):
        return self._stride_length

    @stride_length.setter
    def stride_length(self, value):
        if value > 10:
            raise ValueError("This pedometer is based on the human stride - a stride length above 10m is not supported")
        else:
            self._stride_length = value
Answer from benosteen on Stack Overflow
🌐
Real Python
realpython.com › python-property
Python's property(): Add Managed Attributes to Your Classes – Real Python
December 15, 2024 - However, the decorator approach is more popular in the Python community. You can create a property by calling property() with an appropriate set of arguments and assigning its return value to a class attribute. All the arguments to property() are optional. However, you typically provide at least a getter function. The following example shows how to create a Circle class with a property that manages its radius:
🌐
Programiz
programiz.com › python-programming › property
Python @property Decorator (With Examples)
In this tutorial, you will learn about Python @property decorator; a pythonic way to use getters and setters in object-oriented programming.
🌐
The Python Coding Stack
thepythoncodingstack.com › p › the-properties-of-python-property
The Properties of Python's `property`
April 1, 2025 - To do this, we can change .athlete_id from a data attribute into a property: ... We renamed the data attribute defined in the .__init__() method to ._athlete_id, with a leading underscore. The leading underscore identifies this attribute as non-public. It's not really a private attribute that cannot be accessed from outside the class – Python doesn't have private attributes – but it clearly shows the programmer's intent to any user of this class: this attribute is not meant to be accessed from outside the class.
Top answer
1 of 15
1343

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)
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-property-function
Python property() function - GeeksforGeeks
July 11, 2025 - property() function in Python is a built-in function that returns an object of the property class. It allows developers to create properties within a class, providing a way to control access to an attribute by defining getter, setter and deleter methods. This enhances encapsulation and ensures better control over class attributes. Example...
🌐
Mimo
mimo.org › glossary › python › property
Python property(): Syntax, Usage, and Examples
The deleter decorator allows you to define what happens when del is called on the property. Use the Python property function when you want to implement encapsulation in object-oriented programming:
🌐
Tutorial Teacher
tutorialsteacher.com › python › property-function
Python property() Method
The property() method in Python provides an interface to instance attributes. It encapsulates instance attributes and provides a property, same as Java and C#. The property() method takes the get, set and delete methods as arguments and returns an object of the property class. It is recommended to use the property decorator instead of the property() method. ... Returns the property attribute from the given getter, setter, and deleter. The following example demonstrates how to create a property in Python using the property() function.
Find elsewhere
🌐
Machine Learning Plus
machinelearningplus.com › python › python-property
Python @Property Explained – How to Use and When? (Full Examples)
So a better solution (without breaking your user’s code) is to convert the method as a property by adding a @property decorator before the method’s definition. By doing this, the fullname() method can be accessed as an attribute instead of as a method with '()'. See example below.
🌐
W3Schools
w3schools.com › python › python_class_properties.asp
Python Class Properties
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... Properties are variables that belong to a class.
🌐
IONOS
ionos.com › digital guide › websites › web development › python property
How to use Python property - IONOS
July 20, 2023 - We can use Python property to change or learn the name of our Python dog without having to use an explicit function call. In the following example, we are going to include a print statement in each of our getter and setter methods.
🌐
freeCodeCamp
freecodecamp.org › news › python-property-decorator
The @property Decorator in Python: Its Use Cases, Advantages, and Syntax
December 19, 2019 - Specifically, you can define three methods for a property: A getter - to access the value of the attribute. A setter - to set the value of the attribute. A deleter - to delete the instance attribute. Price is now "Protected" Please note that the price attribute is now considered "protected" because we added a leading underscore to its name in self._price: ... In Python, by convention, when you add a leading underscore to a name, you are telling other developers that it should not be accessed or modified directly outside of the class.
🌐
Programiz
programiz.com › python-programming › methods › built-in › property
Python property()
Become a certified Python programmer. Try Programiz PRO! ... doc (optional) - A string that contains the documentation (docstring) for the attribute. Defaults to None. property() returns the property attribute from the given getter, setter, and deleter.
🌐
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.
🌐
Tutorial Teacher
tutorialsteacher.com › python › property-decorator
Python: Property Decorator @property
Above, @property decorator applied to the name() method. The name() method returns the private instance attribute value __name.
🌐
Python documentation
docs.python.org › 3 › howto › descriptor.html
Descriptor Guide — Python 3.14.3 documentation
Author, Raymond Hettinger,, Contact, ,. Contents: Descriptor Guide- Primer- Simple example: A descriptor that returns a constant, Dynamic lookups, Managed attributes, Cu...
🌐
Scaler
scaler.com › home › topics › python › python @property
Python Property | @property Python - Scaler Topics
May 25, 2022 - Python has a special decorator method called setter method that helps in modifying the value of the function. The syntax of declaring the setter method decorator is: @property-name.setter. Let's take the same Person class example, and learn how to use the setter decorator method to modify the value of a function.
🌐
Reintech
reintech.io › blog › python-practical-uses-for-property-method-tutorial
Python: Practical Uses for the property() Method | Reintech media
January 4, 2026 - In this tutorial for software developers we explain how to use Python's built-in function property() method in your projects. We show how it's useful for encapsulation, data validation, caching and more.
🌐
Python Tutorial
pythontutorial.net › home › python oop › python property
Python Property
March 31, 2025 - The following shows that the Person.age is a property object: ... The john.__dict__ stores the instance attributes of the john object. The following shows the contents of the john.__dict__ : print(john.__dict__)Code language: Python (python)
🌐
Real Python
realpython.com › ref › builtin-functions › property
property() | Python’s Built-in Functions – Real Python
The most common use cases for the property() function include the following: Creating read-only, read-write, or write-only attributes ... Here’s an example where you use property() to manage a circle’s radius and diameter.