I am pretty new to OOP in python (ver. 3.5). I created a generic class and I would like to create a new one inheriting from it.
My parent class (say
) has two args defined within its
method. How can I inherit those in my child class (say
) so that when I instantiate
I can pass it the args I would pass to
? I am actually trying to use the
function, but I am not quite sure about the result.
I tried the below, but it gives me
TypeError: __init__() takes 1 positional argument but 3 were given
class A(): # parent class
def __init__(self, x, y):
self.x = x
self.y = y
class B(A): # child class
And then I would do (e.g.)
b = B(5, 5)
As my question was identified as duplicate of this answer
, I would lke to state why it is different and why that answer did not help me to solve my problem:
I am not asking about how to access the parameters of a parent class from a child class, but if it was possible to instantiate a class with a parent class inherited, passing to it the arguments like if it was a call to the parent's class.
The answer is "I can't", unless I define again the same arguments in the child class
method. Finally, as I said I am new to OOP, the indicated answer was not helpful, as the initial question was too difficult to understand to me (and it's not even in python).