Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 类中的方法将不接受参数_Python_Python 3.x - Fatal编程技术网

Python 类中的方法将不接受参数

Python 类中的方法将不接受参数,python,python-3.x,Python,Python 3.x,我是Python新手,我只是尝试创建一个简单的类来测试它。我在“Patient”类中定义我的方法时使用了自参数,但在尝试构建时仍然得到“takesnoaarguments错误”。这是我试图运行的代码 class Patient: def _init_(self,name,weight=0,LegLen=0): self.name = name self.weight = weight self.LegLen = LegLen Mark

我是Python新手,我只是尝试创建一个简单的类来测试它。我在“Patient”类中定义我的方法时使用了自参数,但在尝试构建时仍然得到“takesnoaarguments错误”。这是我试图运行的代码

class Patient:
    def _init_(self,name,weight=0,LegLen=0):
        self.name = name
        self.weight = weight
        self.LegLen = LegLen


Mark = Patient('Mark')
print(Mark.name)
然后我得到了错误。。。 标记=患者(“标记”) TypeError:Patient()不接受任何参数


我做错了什么?

应该将
\u init\u
拼写为
\u init\u
(双下划线)。否则,它只是一个与其他方法一样的方法,而不是构造函数。

应该将
\u init\u
拼写为
\u init\u
(双下划线)。否则,它只是一个和其他方法一样的方法,而不是构造函数。

@mitchelleefers:我很乐意。对于某些字体,实际上很难看出区别,因为两个下划线连接在一起形成一条直线。@Mitchelleeffers:我的荣幸。对于某些字体,实际上很难看到区别,因为两个下划线连接在一起并形成一条直线。