Python bypassing @property getter methods ambiguity

49 Views Asked by At

I know that this is a badly written code. But why does this behave this way?

class A:
    def __init__(self, f, l):
        self.first = f
        self.last = l
        
    @property
    def first(self):
        return self._first
    @first.setter
    def first(self, new):
        self._first = new
        

a = A("ab", "cd")
print(a.first)

Why does this return "ab"? Shouldn't the @property getter method be invoked on a.first and raise an attribute error?

0

There are 0 best solutions below