weixin_慕慕6076839
2021-12-14 15:32
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’,所以,知道为什么了吧~
Python3 进阶教程(新版)
41910 学习 · 236 问题
相似问题