1)使用属性:
getter 和setter
class Duck():
def __ init__(self,input_name):
self.hiddle_name=input_name
def get_name(self):
print("inside the gutter")
return self.hiddle_name
def set_name(self,input_name):
print("inside the setter")
self.hiddle_name=input_name
name=property(get_name,set_name)
get_name(输出值)getter
set_name(修改值)setter
class Duck():
def __ init__(self,input_name):
self.hiddle_name=input_name
@property
def name(self):
print("inside the gutter")
return self.hiddle_name
@name.setter
def name(self,input_name):
print("inside the setter")
self.hiddle_name=input_name
name=property(get_name,set_name)
fowl.Duck__name
“donald”