I have 3 classes A,B and D as given below
class A(object):
def test(self):
print "called A"
class B(object):
def test(self):
print "called B"
class D(A,B):
def test(self):
super(A,self).test()
inst_d=D()
inst_d.test()
----------------------------------------
Output:
called B
Question: In D.test()
, I am calling super(A,self).test()
. Why is only B.test()
called even though the method A.test()
also exists?
Because you've told it not to. In D.test
you've told it to call the test method of the parent of A - that's what super
does.
Normally you want to use the current class name in the super
call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With