简体   繁体   English

Traceback(最近一次通话最后一次):文件“<stdin> &quot;,第 1 行,在<module> TypeError: object() 没有参数

[英]Traceback (most recent call last): File "<stdin>", line 1, in <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

I want to know where I went wrong and how can I resolve this.我想知道我哪里出错了,我该如何解决这个问题。

__init__() is a dunder. __init__()是一个笨蛋。 It starts and ends with __ , a double underbar, aka: dunder.它以__开头和结尾,一个双下划线,又名:dunder。 Change _init_ to __init__ .__init__ _init_

Code:代码:

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

    def display(self):
        return ("this is a " + self.name + str(self.age))

stu = student("chad", 14)
print(stu.display())

Results:结果:

this is a chad14

Try this:尝试这个:

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()

Just put a new line after the class definition.只需在类定义后换行即可。
Also, I solved some errors in your code.另外,我解决了您代码中的一些错误。

>>> 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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 追溯(最近一次通话):“文件” <stdin> ”,第1行,在 <module> - Traceback (most recent call last): File “<stdin>”, line 1, in <module> Traceback(最近一次调用最后一次):文件“<stdin> ”,第 1 行,在<module> ModuleNotFoundError:没有名为“Webhook”的模块</module></stdin> - Traceback (most recent call last): File “<stdin>”, line 1, in <module> ModuleNotFoundError: No module named 'Webhook' 获取回溯(最近一次调用最后一次):文件“<stdin> &quot;,第 1 行,在<module> NameError:名称“文件名”未定义 - Getting Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'filename' is not defined 回溯(最近调用最后):文件“<stdin> ",第 1 行,在<module> NameError: 名称 'db' 未定义</module></stdin> - Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'db' is not defined 我可以逃避此错误回溯(最近一次通话是最近一次):“文件” <stdin> ”,第1行,在 <module> 档案“ <stdin> ”,第2行,在data_entry中 - can i escape this error Traceback (most recent call last): File “<stdin>”, line 1, in <module> File “<stdin>”, line 2, in data_entry 回溯(最近调用最后):文件“main.py”,第 12 行,在<module>授权错误:TypeError: 'bool' object is not iterable</module> - Traceback (most recent call last): File "main.py", line 12, in <module> for error in authorisation: TypeError: 'bool' object is not iterable 为什么“回溯(最近一次通话最后一次):文件”<stdin> ”,第 1 行,在<module> ImportError:当我尝试安装 django 时,没有名为 django 的模块?</module></stdin> - why 'Traceback (most recent call last): File “<stdin>”, line 1, in <module> ImportError: No module named django' when im trying to install django? 无法在python 3Traceback(最近一次调用为最新)中找出此错误:“文件” <stdin> ”,第1行,在 <module> NameError:未定义名称“ xlrd” - Cannot figure out this error in python 3Traceback (most recent call last): File “<stdin>”, line 1, in <module> NameError: name 'xlrd' is not defined Python TypeError Traceback(最近一次调用最后一次) - Python TypeError Traceback (most recent call last) 追溯(最近一次呼叫过去):和TypeError: - Traceback (most recent call last): and TypeError:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM