Hello all,
Base is parent and Child inherited .
Should argument(s) in the __init__of the child class be same as what we have in the __init__ 's parent?
I get an error.
After trying to make an object from Child Class :
Base is parent and Child inherited .
Should argument(s) in the __init__of the child class be same as what we have in the __init__ 's parent?
I get an error.
1 2 3 4 5 6 |
class Base(): def __init__( self ,a,b): self .a = a self .b = b print ( "From Parent Class" ) |
1 2 3 4 5 |
class Child(Base): def __init__( self ): super ().__init__( self ,a,b) # or Base.__init__(self,a,b) print ( "From Child Class" ) |
1 |
childobject = Child() |
Error:NameError Traceback (most recent call last)
<ipython-input-80-3762dc95e937> in <module>
----> 1 childobject=Child()
<ipython-input-79-b57528e5fe56> in __init__(self)
2
3 def __init__(self):
----> 4 super().__init__(self,a,b)
5 print("From Child Class")
NameError: name 'a' is not defined