Call overridden method of parent class with child class object in python -
i have came around question during interview:
class parent(object): def a(self): print "in a" class child(parent): def a(self): print "in b" c=child()
question come here:
is there way can call parent class function
a
child object @ instance level without doing changes in classes?
have searched many question didn't find satisfactory answer.please reply.
thanks.
you can use super()
builtin.
>>> super(child, c).a() in
it used call super class implementation inside subclasses, allowed outside. docs state:
also note super() not limited use inside methods. 2 argument form specifies arguments , makes appropriate references.
Comments
Post a Comment