class Animal(object):
def __init__(self, name, age, localtion):
self.__name = name
self.__age = age
self.__localtion = localtion
def get_info(self):
return 'name = {}, age = {}, localtion = {}'.format(self.__name, self.__age, self.__localtion)
def change_info(self,name,age,location):
self.__name = name
self.__age = age
self.__location = location
dog = Animal('wangwang', 1, 'GuangDong')
print(dog.get_info())
dog.change_info('wangcai',3,'Error')
print(dog.get_info())
标注为Error的为最后输出错误的地方
结果仍为“GongDong”
书写是个大问题。
害人不浅啊~
在__init__里的是‘localtion’,在change_info里的是‘location’,所以,知道为什么了吧~