Answer the question
In order to leave comments, you need to log in
How can a class be given an init subclass?
How, when creating an object, to specify the value of the arguments for both Ball and separately for Model?
those. 4 arguments
class Model():
def __init__(self, name, size):
self.name = name
self.size = size
def crt(self):
return self.name + self.size
class Ball(Model):
def __init__(self,width,height):
self.width = width
self.height = height
def move(self):
return self.width + self.height
play = Ball(200,100)
play.crt() - не сработает
Answer the question
In order to leave comments, you need to log in
>>> class Model():
... def __init__(self, name, size):
... self.name = name
... self.size = size
... def crt(self):
... return self.name + self.size
...
>>>
class Ball(Model):
def __init__(self,width,height, *args, **kwargs):
self.width = width
self.height = height
super().__init__(*args, **kwargs)
def move(self):
return self.width + self.height
...
>>> play = Ball(200, 100, 2, 3)
>>> play.crt()
5
>>> play.move()
300
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question