没明白这个参数修改是怎么搞的?
class Animal(object): def __init__(self, name, age, localtion): self.__name=name self.__age=age self.__localtion=localtion def get_name(self): return self.__name def get_age(self): return self.__age def get_location(self): return self.__location def set_info(self): self.__name=name self.__age=age self.__localtion=localtion monkey=Animal('wukong',25,'China') print(monkey.get_name()) monkey.set_info() monkey.__name='Monkeyking' print(monkey.get_name())
File "C:/Users/Administrator.USER-20190923TT/PycharmProjects/untitled/learn", line 60, in <module>
monkey.set_info()
File "C:/Users/Administrator.USER-20190923TT/PycharmProjects/untitled/learn", line 55, in set_info
self.__name=name
NameError: name 'name' is not defined