خرید بک لینک

Vote count: 0

I am new to Python and I just discovered the properties. It works just fine when I try it on a simple variable but I caot make it work on a list. When executing the code below it will call two times the getter and not the setter. I know that in my example the property has no added value but it is to simplify.

class C:
def __init__(self):
    self._x=[1,2,3]

@property
def x(self):
    print("getter")
    retu self._x
@x.setter
def x(self,value):
    print("setter")
    self._x=value

c = C()
c.x[1]=4
print(c.x[1])

Does anybody have an idea about what I'm doing wrong ?

Thanks,

asked 2 mins ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 12 خرداد 1395 ساعت: 16:51

صفحه بندی