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. 即时通讯ping
- 3. PHP中的即时通讯?
- 4. 即时通讯实施?
- 5. 在android上即时通讯?
- 6. Java即时通讯问题
- 7. 即时通讯错误,当我试图重写这个网址
- 8. 即时通讯坚持这个问题
- 9. 即时通讯使用nuance omnipage OCR SDK即时通讯内容OCR SDK Engine.SetLicenseKey()
- 10. 我正在使用spring + hibernate和即时通讯得到错误:org.springframework.dao.InvalidDataAccessResourceUsageException
- 11. 即时通讯有错误检查和循环
- 12. JavaScript文件返回错误日志,即时通讯不知道
- 13. 要解决在ATM程序即时通讯使用java的两个错误
- 14. Java中的即时通讯实现
- 15. 使用PHP的Ajax即时通讯
- 16. 任何开源即时通讯软件?
- 17. 即时通讯问题?与ASP.NET冲突?
- 18. 使用Flask-socketIO即时通讯
- 19. 即时通讯.NET序列化转换
- 20. Django中的AJAX即时通讯工具
- 21. 即时通讯实现的轨道?
- 22. 即时得到一个错误在我的课在Eclipse
- 23. 嗨,即时通讯JAVA学生,编译时,我得到以下消息,试图建立一个Java的GUI
- 24. 寻找一个PHP即时通讯解决方案
- 25. 计算与MySQL即时通讯工作了一个麻烦
- 26. 即时得到使用objectFromJSONData
- 27. 标签显示不能与iPhone应用程序即时通讯
- 28. 通过即时通讯客户端接收PubSub通知
- 29. ASP.NET MVC2即时404错误
- 30. vb.net即时获取错误
您错过了您的班级名称,例如: 'reg1 = EceA('sam',21)',你缺少'disp()'的'instance'变量。注意调用'instance'变量'self'是很传统的(你在'__init __()'中使用了''''这些都是基本的错误,我会阅读更多初学者的教学材料 – AChampion