class EceA:
def __init__(s,name,age):
s.name = name
s.age = age
def disp():
return("the student name is" + s.name +"and the age is"+str(s.age))
reg1=("sam",21)
Traceback (most recent call last):
File "<pyshell#27>", line 1, in <module>
reg1.disp
AttributeError: 'tuple' object has no attribute 'disp'
-3
A
回答
1
你需要讓類的一個對象與參數:
reg1 = EceA("sam",21)
reg1.disp()
還需要self
放慢參數傳遞給disp()
功能,如:
def disp(self):
return("the student name is" + self.name +"and the age is"+str(self.age))
此外,在init
您應該通過'self
'而不是's
'作爲第一個參數
+1
'''''''使用'str.format()'可能是一種更好的方法:'返回'學生姓名是{0.name},年齡是{0.age}「。format(self)' – AChampion
+0
謝謝先生。非常感謝你幫助我。 –
相關問題
- 1. Android notepadv2教程...即時通訊錯誤
- 2. 爲什麼即時通訊錯誤?
- 3. 即時通訊ping
- 4. 當即時通訊嘗試進入一個相對路徑即時通訊得到一個錯誤startindex不能小於零
- 5. 即時通訊實施?
- 6. 在android上即時通訊?
- 7. PHP中的即時通訊?
- 8. C#即時通訊幫助
- 9. jQuery .hide()即時通訊做錯事
- 10. 即時通訊錯誤,當我試圖重寫這個網址
- 11. 即時通訊堅持這個問題
- 12. W/System.err:org.json.JSONException:沒有值的飼料..即時通訊獲取此錯誤..即時通訊使用flickr API
- 13. 即時通訊使用nuance omnipage OCR SDK即時通訊內容OCR SDK Engine.SetLicenseKey()
- 14. 即時通訊使用的時間包
- 15. 我正在使用spring + hibernate和即時通訊得到錯誤:org.springframework.dao.InvalidDataAccessResourceUsageException
- 16. 要解決在ATM程序即時通訊使用java的兩個錯誤
- 17. JavaScript文件返回錯誤日誌,即時通訊不知道
- 18. 即時通訊有錯誤檢查和循環
- 19. 爲什麼即時通訊錯誤在行InitializeComponent();?
- 20. 使用Neo4j進行即時通訊webApp
- 21. 使用Flask-socketIO即時通訊
- 22. 即時通訊實現的軌道?
- 23. 即時通訊.NET序列化轉換
- 24. 即時通訊問題?與ASP.NET衝突?
- 25. 任何開源即時通訊軟件?
- 26. 使用PHP的Ajax即時通訊
- 27. 在因爲即時通訊新軌軌
- 28. C#WP8即時通訊 - 如何?
- 29. Java中的即時通訊實現
- 30. 開源即時通訊軟件?
您錯過了您的班級名稱,例如: 'reg1 = EceA('sam',21)',你缺少'disp()'的'instance'變量。注意調用'instance'變量'self'是很傳統的(你在'__init __()'中使用了''''這些都是基本的錯誤,我會閱讀更多初學者的教學材料 – AChampion