所以这是我的代码,我试图让 Rectangle 类从对象类继承。我不明白对象类是什么意思,以及如何继承它。
class Rectangle:
def __init__(self, coords, sizex, sizey):
self._startx, self._starty = coords
self._sizex = sizex
self._sizey = sizey
def getBottomright(self):
'(%s, %s)' % (self._startx + self._sizex, self._starty + self._sizey)
def move(self, pos):
self._startx, self._starty = pos
def resize(self, width, height):
self._sizex = width
self._sizey = height
def __str__(self):
return '((%s, %s), (%s, %s))' % (self._startx, self._starty, self._startx + self._sizex, self._starty + self._sizey)
r = Rectangle((2, 3), 5, 6)
print str(r)
'((2, 3), (7, 9))'
r.move((5, 5))
print str(r)
'((5, 5), (10, 11))'
r.resize(1,1)
print str(r)
'((5, 5), (6, 6))'
r.getBottomright()
(6, 6)