python----特性003

python特性003:计算特性

#!/usr/local/bin/python3.5

class MyNumber(object):
    def __init__(self,number):
        self.number=number
    def get_number(self):
        ####对于返回值可以有计算
        return self.number*2
    def set_number(self,number):
        self.number=number
    def del_number(self):
        del self.number
    Number=property(get_number,set_number,del_number,'Number property ...')

if __name__=="__main__":
    n=MyNumber(100)
    print(n.Number)

 

posted on 2016-08-07 14:33  蒋乐兴的技术随笔  阅读(143)  评论(0编辑  收藏  举报

导航