Last modified: Nov 27, 2026
Python Class Property vs Attribute
Many beginners use the words attribute and property as if they mean the same thing. They do not.
In Python, an attribute is a simple value stored on an object. A property is a method that acts like an attribute.
This guide explains both clearly. You will see code, output, and the main rules for choosing one over the other.
What Is an Attribute?
An attribute is data attached to an object. You create it in __init__ or set it later.
You read and write it with dot notation. There is no logic behind it. It is just a value.
class Circle:
def __init__(self, radius):
self.radius = radius # plain attribute
c = Circle(5)
print(c.radius) # read the attribute
c.radius = 8 # write the attribute
print(c.radius)
5
8
This is fast and simple. But it has one weakness. Nothing checks the value you assign.
You can set c.radius = -10 and Python will not complain. A negative radius makes no sense.
What Is a Property?
A property is a special attribute backed by a method. It looks like data from the outside, but it runs code inside.
You create it with the built-in property() function or with the @property decorator. The decorator is the common choice.
class Circle:
def __init__(self, radius):
self._radius = radius # protected attribute
@property
def radius(self):
return self._radius
@radius.setter
def radius(self, value):
if value < 0:
raise ValueError("Radius cannot be negative")
self._radius = value
c = Circle(5)
print(c.radius) # calls the getter
c.radius = 10 # calls the setter
print(c.radius)
5
10
The user still writes c.radius. But now a method runs behind the scenes.
Try to set a bad value and the setter rejects it.
c.radius = -3
ValueError: Radius cannot be negative
This is the core benefit of a property. You get validation and control without changing the public interface.
The Key Differences
Here is a quick comparison of the two concepts.
Storage: An attribute stores data directly. A property stores data in another attribute and controls access to it.
Logic: An attribute has no logic. A property can run any code when read or written.
Speed: An attribute is slightly faster. A property adds a small method call overhead.
Interface: Both use dot notation. Code that reads obj.name works the same for either one.
Validation: Only a property can validate or transform values on assignment.
Why Properties Exist
Python has no private variables. Everything is public by convention.
If you start with a plain attribute, users may depend on it. Later you may need checks or computed values.
A property lets you add that logic without breaking existing code. The call site stays the same.
This is why the @property decorator is so common in real projects. It is also a common topic when learning when to use property in Python.
Read-Only Properties
Sometimes you want a value that can be read but not changed. A property with no setter does exactly that.
class Temperature:
def __init__(self, celsius):
self._celsius = celsius
@property
def fahrenheit(self):
return self._celsius * 9 / 5 + 32 # computed value
t = Temperature(25)
print(t.fahrenheit)
77.0
The fahrenheit value is computed on demand. It is never stored. If someone tries t.fahrenheit = 100, Python raises an AttributeError.
This pattern keeps data consistent. There is only one source of truth, the Celsius value.
Properties That Take Arguments
A property getter takes only self. You cannot pass extra arguments to it.
If you need parameters, use a normal method instead. This is a common point of confusion, and you can read more in Python Property with Arguments.
class Box:
def __init__(self, side):
self.side = side
@property
def area(self):
return self.side ** 2
def scaled_area(self, factor): # method, not property
return self.area * factor
b = Box(4)
print(b.area)
print(b.scaled_area(2))
16
32
Remember the rule. Use a property for simple access. Use a method when you need inputs.
Attributes on Lists and Built-in Objects
Not every attribute belongs to your own class. Built-in objects have attributes too.
Lists, for example, expose methods like append and sort. Understanding these helps you see attributes in action, as covered in Python List Object Properties.
numbers = [3, 1, 2]
numbers.sort() # method call, changes the list
print(numbers)
print(numbers.count(2)) # method returns a value
[1, 2, 3]
1
These are methods, not properties. The distinction matters when you design your own classes.
Common Mistakes
Beginners often make a few predictable errors with properties.
Mistake 1: Naming the backing attribute the same as the property. This causes infinite recursion.
class Bad:
@property
def value(self):
return self.value # RecursionError!
RecursionError: maximum recursion depth exceeded
The fix is a leading underscore, like self._value. That name avoids the clash.
Mistake 2: Using a property for heavy work. A property should feel instant. Long loops or network calls belong in a method.
Mistake 3: Adding properties everywhere. Plain attributes are fine for simple data. Use properties only when you need control.
When to Use Each One
Use a plain attribute when the value is simple and needs no checks. Use a property when you need validation, computed values, or lazy loading.
Also use a property when you want to protect an attribute from outside changes. A read-only property is a clean way to expose derived data.
Start simple. You can always convert an attribute to a property later without breaking the interface.
Properties and Methods Inside Classes
Every method in a class receives self as its first argument. This includes property getters and setters.
If you are new to this, the __init__ method is the best place to start. It runs when an object is created and sets the initial attributes.
class User:
def __init__(self, name):
self._name = name # set in __init__
@property
def name(self):
return self._name.title() # formatted on read
The __init__ method and self work together to build each object. A property then controls how that data is read or changed.
Conclusion
An attribute is simple stored data. A property is a method that behaves like an attribute.
Both use the same dot notation, so users see no difference. The difference is in control.
Use attributes for plain values. Use properties for validation, computed values, and read-only access.
Keep properties light and predictable. Avoid recursion by using underscore names for backing attributes.
With these rules, your Python classes will be safer, cleaner, and easier to maintain.