I am trying to make a subclass, Square, from a superclass, Shape.
class Shape :
def __init__ (self, x, y) :
self.x = x
self.y = y
self.description = "This shape has not been described yet"
def area (self) :
return self.x * self.y
def describe (self, text) :
self.description = text
I have tried
class Square (Shape) :
def __init__ (self, x) :
self.x = x
self.y = x
self.description = "This shape has not been described yet"
which seems to work, but the only thing that actually changes in Square is self.y = x, so I wonder if I could do the same thing without having to write self.x and self.description again.
(I tried doing something like this:
class Square (Shape) :
def __init__ (self, x) :
self.y = x
super().__init__()
but, when I create a Square object, a type error occurs: TypeError: init() missing 2 required positional arguments: 'x' and 'y')