yes it does but @property decorator make it more neat and tidy to define multiple property in a class.
Property is Different with attribute. The reason property used in encapsulation because python don't have built-in access modifier. In fact, when we call @property decorator above a method we instantiate a property object. Property object is an object have get,set, and del method. Property can be defined in a class without the need to define it in init. init method invoked when an object instantiated. If the private attribute need to set when the object created define it in init but when we don't need initial value we have no need to define the attributes. Here's the example of property without attribute.
class C(object):
#X Property
@property
def x(self):
"""I'm the 'x' property."""
print('Get The X Property')
return self._x
@x.setter
def x(self, value):
print('X Property Setted to {}'.format(value))
self._x = value
@x.deleter
def x(self):
print('X is Killed !')
del self._x
#Y Property
@property
def y(self):
"""I'm the 'y' property."""
print('Get The Y Property')
return self._y
@y.setter
def y(self, value):
print('Y Property Setted to {} '.format(value))
self._y = value
@y.deleter
def y(self):
print('Y is Killed !')
del self._y
When we need to define x and y as an attribute to the class C. Just set the the attribute in init. so, x and y listed as class C attribute and have initial value setted when the object instantiated.
class C(object):
def __init__(self):
self._x = 0
self._y = 0
#X Property
@property
def x(self):
"""I'm the 'x' property."""
print('Get The X Property')
return self._x
@x.setter
def x(self, value):
print('X Property Setted to {}'.format(value))
self._x = value
@x.deleter
def x(self):
print('X is Killed !')
del self._x
#Y Property
@property
def y(self):
"""I'm the 'y' property."""
print('Get The Y Property')
return self._y
@y.setter
def y(self, value):
print('Y Property Setted to {} '.format(value))
self._y = value
@y.deleter
def y(self):
print('Y is Killed !')
del self._y
The Difference is simple. Without any initial value the class C have no x and y attributes. so, if we trying to get the attribute an exception will raised. With initial value the class C already have X and Y attribute from the beginning.