我是python编程的初学者。我一直遇到一个类型错误:object()不接受任何参数,我不知道如何修复它。我该怎么办
import matplotlib.pyplot as plt
%matplotlib inline
class Rectangle(object):
def _init_(self, height, width, color):
self.height = height
self.width = width
self.color = color
def add_height(self,h):
self.height = self.height + h
return(self.height)
def add_width(self,w):
self.width = self.width+w
return(self.width)
def drawRectangle(self):
plt.gca().add_patch(plt.Rectangle(0,0), self.height, self.width, fc=self.color)
plt.axis('scaled')
plt.show()
bluerectangle = Rectangle(5, 3, 'blue')
#I get the error after I create the object bluerectangle
__init__
需要下划线,而不是每边只有一个所以你需要
因为init方法拼写不正确,所以它没有覆盖
object
的init方法,这解释了为什么python抱怨object()
不带参数相关问题 更多 >
编程相关推荐