課程
/后端開發
/Python
/Python3 進階教程(新版)
實例中無法傳遞類參數,會報錯提示Animal類中不需要參數,但是后面調用的方法需要傳遞3個參數
2021-11-17
源自:Python3 進階教程(新版) 2-8
正在回答
class Animal(object):
? ??
? ? def __init(self,name,age,location):
? ? ? ? self.__name = name
? ? ? ? self.__age = age
? ? ? ? self.__location = location
? ? ? ??
? ? def set_name(self,name):
? ? ? ? self._name = name
? ? def get_name(self):
? ? ? ? return self._name
? ? def set_age(self,age):
? ? ? ? self._age= age
? ? def get_age(self):
? ? ? ? return self._age
? ? def set_location(self,location):
? ? ? ? self._location = location
? ? def get_location(self):
? ? ? ? return self._location
dog= Animal()
print(dog.__name)
把你的代碼貼出來看一下
舉報
學習函數式、模塊和面向對象編程,掌握Python高級程序設計
1 回答參考答案是錯誤的,沒有考慮換行符
2 回答我在IDLE中輸入參考答案代碼為什么運行了但是沒有任何顯示呢
2 回答想請教一下參考答案中定義修改set方法,要怎么調用呢
2 回答為什么創建實例的時候count不會被重置到0?
2 回答看不懂,參考答案為什么要這樣編輯?有沒有大神指導一下?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2021-11-21
class Animal(object):
? ??
? ? def __init(self,name,age,location):
? ? ? ? self.__name = name
? ? ? ? self.__age = age
? ? ? ? self.__location = location
? ? ? ??
? ? def set_name(self,name):
? ? ? ? self._name = name
? ??
? ? def get_name(self):
? ? ? ? return self._name
? ??
? ? def set_age(self,age):
? ? ? ? self._age= age
? ??
? ? def get_age(self):
? ? ? ? return self._age
? ? ? ??
? ? def set_location(self,location):
? ? ? ? self._location = location
? ??
? ? def get_location(self):
? ? ? ? return self._location
dog= Animal()
print(dog.__name)
2021-11-18
把你的代碼貼出來看一下