[英]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_
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())
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.