追溯(最近调用最后):文件“<stdin>”,第 1 行,在 <module> TypeError: object() takes no parameters

新手上路,请多包涵
>>> class student:
    def _init_(self,name,age):
        self.name
        self.age
    def display(self):
        return("this is a "+self.name+str(self.age))
>>> stu=student("chad",14)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object() takes no parameters

我想知道我哪里出错了,我该如何解决。

原文由 Ben 10 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 601
1 个回答

尝试这个:

 class student:
  def __init__(self,name,age):
    self.name = name
    self.age = age

  def display(self):
    stu=student("chad",14)
    print("this is a "+(stu.name)+str(stu.age))

s = student(None,None)
s.display()

原文由 Shehan Dhaleesha 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题