property装饰器

property装饰器示例

class  Person:

  def __init__(self,name):

    self.__name=name  

  def getname(self):

    return self.__name

  def setname(self,value)

    self.__name=value

  def delname(self):

    def  self.__name

  name=property(getname,setname,delname,"i am the name property")

if  __name__=="__main__":

  p=Person('11111')

  print(p.name)

  p.name="22222"

  print(p.name)

 

posted @ 2018-06-28 08:53  duxiao123  阅读(53)  评论(0编辑  收藏  举报