想请教一下参考答案中定义修改set方法,要怎么调用呢
想请教一下参考答案中定义修改set方法,要怎么调用呢
想请教一下参考答案中定义修改set方法,要怎么调用呢
2022-01-07
class Animal():
def __init__(self,name,age,location):
self.__name=name
self.__age=age
self.__location=location
def get_info(self):
return 'name={},\nage={},\nlocation={}'.format(self.__name,self.__age,self.__location)
def set_name(self,name):
self.__name=name
def set_age(self,age):
self.__age=age
def set_location(self,location):
self.__location=location
dog=Animal("hashiqi",4,"guangzhou")
print(dog.get_info())
print("")
dog.set_location("tianjin")
print(dog.get_info())
举报