Last modified: Nov 27, 2026
What Does Property Do in Python?
The property decorator is one of the most useful tools in Python. It lets you turn a method into a managed attribute. You can read, write, and delete it like a normal attribute.
Behind the scenes, your code runs when you access it. This gives you full control over what happens.
This article explains what property does, why it matters, and how to use it well.
Why Property Exists
In many languages, you hide data behind getter and setter methods. Python takes a cleaner path.
You start with a simple public attribute. Later, you may need validation or extra logic. Instead of breaking every caller, you switch to a property.
The public interface stays the same. Only the internals change. This keeps your code backward compatible.
The Basic Syntax
You apply the property decorator to a method. That method becomes the getter. You can also define a setter with @name.setter.
class Circle:
def __init__(self, radius):
self._radius = radius # private storage
@property
def radius(self):
return self._radius # runs when you read circle.radius
@radius.setter
def radius(self, value):
if value < 0:
raise ValueError("Radius cannot be negative")
self._radius = value # runs when you assign
c = Circle(5)
print(c.radius) # getter runs
c.radius = 10 # setter runs
print(c.radius)
5
10
Notice that c.radius looks like a plain attribute. It is not. Python calls your method for you.
Validation on Assignment
The setter is where validation shines. You can reject bad values before they reach your object.
Without a property, users could set any value. With a property, you enforce rules in one place.
This pattern is covered in depth in the Python class property setter guide. It shows more examples of guarding state.
Computed Attributes
A property can also calculate a value on demand. You do not store it. You compute it each time.
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
@property
def area(self):
return self.width * self.height # computed, not stored
r = Rectangle(4, 3)
print(r.area)
12
This keeps data consistent. The area always reflects the current width and height.
Read-Only Properties
If you define only a getter, the attribute becomes read-only. Any assignment raises an error.
This is perfect for values that should never change from outside the class.
You can read more about read-only behavior in the Python class level property guide.
Property vs Plain Attribute
Plain attributes are fast and simple. Properties add a small overhead. Use them only when you need logic.
Do not wrap every attribute in a property by default. That adds noise without benefit.
For a side-by-side comparison, read Python class property vs attribute.
Deleting with a Deleter
You can also define a deleter. It runs when someone uses del on the attribute.
class Temp:
def __init__(self):
self._value = 42
@property
def value(self):
return self._value
@value.deleter
def value(self):
print("Deleting value")
del self._value # cleanup runs here
t = Temp()
del t.value
Deleting value
Deleters are less common. They are useful for cleanup or releasing resources.
Properties with Arguments
A property cannot take extra arguments directly. It only receives self.
If you need parameters, return a callable or use a method. Learn the patterns in Python property with arguments.
How Property Relates to self
Every property method receives self as its first argument. That is how Python knows which instance to work with.
If self feels confusing, review what is self in Python explained. It breaks down the concept clearly.
You can also see a concrete Python self parameter example and a guide on Python self parameter in classes.
Coming from Java? The comparison in Python self vs Java this: key differences will help.
Common Mistakes
One common mistake is naming the backing field the same as the property. This causes infinite recursion.
Always use a different name, like _radius. The underscore signals internal use.
Another mistake is adding heavy work in a getter. Getters should stay fast and predictable.
Also, avoid side effects in getters. Reading an attribute should not change state.
When to Use Property
Use a property when you need validation, computed values, or lazy loading. Use it when you want to keep a clean public API.
Skip it when a plain attribute is enough. Simplicity wins.
For guidance on choosing, read when to use property in Python.
Note that built-in types like lists have their own attributes. Those are different from user-defined properties. See Python list object properties.
Property and Performance
Properties are slightly slower than plain attributes. Each access calls a function.
In most programs, this cost is negligible. Optimize only when profiling shows a real problem.
For hot loops, consider caching computed values. But keep the cache correct.
Conclusion
The property decorator turns methods into managed attributes. It gives you validation, computed values, and read-only access without changing your public API.
Start simple. Add properties only when logic is needed. Keep getters fast and setters strict.
With these habits, your classes stay clean, safe, and easy to maintain.