I saw in another question that you can get and set class attributes like so:
class SomeClass:
def __init__(self, name):
self.name = name
@property
def name(self):
return self._name
@name.setter
def name(self, val):
self._name = val
I'm just wondering why we do this when it looks like I can also just do:
x = SomeClass(name='Ari')
x.name = 'StackOverflow'
Can someone explain to me the purpose of the @property
and @<attribute>.setter