property与x.setter与x.deleter

#测试property,x.setter,x.deleter
class Test1:
    def __init__(self):
        self.__private = "alex"

    @property
    def private(self):
        return self.__private

    @private.setter
    def private(self,value):
        self.__private = value

    @private.deleter
    def private(self):
        del self.__private

t1 = Test1()
print(t1.private)
t1.private = "alex2"
print(t1.private)
del t1.private
print(t1.private)

 

posted @ 2019-01-10 15:34  shengguorui  阅读(153)  评论(0编辑  收藏  举报