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)
时间: 2024-10-05 09:53:06