A setter : Method : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » Method »

 

A setter


class HideX(object):
    def __init__(self, x):
        self.x = x

    def get_x(self):
        return ~self.__x

    def set_x(self, x):
        assert isinstance(x, int)'"x" must be an integer!'
        self.__x = ~x

    x = property(get_x, set_x)

inst = HideX(20)
print inst.x
inst.x = 30
print inst.x



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Class
» Method