朝露待日晞 发表于 2018-1-19 17:10:20

python TypeError求助

为什么我抄小甲鱼的程序,结果会是这样呢?

>>> class Rectangle:
        def _init_(self,x,y):
                self.x = x
                self.y = y
        def getPeri(self):
                return (self.x + self.y)*2
        def getArea(self):
                return self.x * self.y

       
>>> rect = Rectangle(3,4)
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
    rect = Rectangle(3,4)
TypeError: object() takes no parameters

BngThea 发表于 2018-1-19 17:14:03

init左右两边是两个下划线

朝露待日晞 发表于 2018-1-20 14:51:24

BngThea 发表于 2018-1-19 17:14
init左右两边是两个下划线

多谢多谢!!
页: [1]
查看完整版本: python TypeError求助