Python TypeError:Person()不接受任何参数

Python TypeError:Person()不接受任何参数,python,Python,我是python新手,正在尝试创建类。每次运行此代码时,都会出现错误TypeError:Person不接受任何参数。 我不知道为什么争论没有传递到课堂上 class Person: def _init_(self,name,age): self.name=name self.age=age def myfun(self): print("my name is"+self.name) print("my age is"

我是python新手,正在尝试创建类。每次运行此代码时,都会出现错误TypeError:Person不接受任何参数。 我不知道为什么争论没有传递到课堂上

class Person:
    def _init_(self,name,age):
        self.name=name
        self.age=age
    def myfun(self):
        print("my name is"+self.name)
        print("my age is"+self.age)

p1=Person("John",29)
p1.myfun()

构造函数必须命名为uu init uuu,而不是u init。

构造函数必须命名为uu init uuu,而不是u init。

您应该在init的神奇方法中再添加1个uu,并用两个下划线换行

它可以工作

你应该在它的魔术方法中再加1个,并用两个下划线换行


它工作了

谢谢,它现在工作了
class Person:
   def __init__(self,name,age):
       self.name=name
       self.age=age
   def myfun(self):
       print("my name is"+self.name)
       print("my age is"+self.age)

p1=Person("John",29)
p1.myfun()