Suppose I have two classes (one a parent and one a subclass). How do I refer to a method in the parent class if the method is also defined in the subclass different?
Here is the code:
class A:
def __init__(self, num):
self.value=num
def f(self, num):
return self.value+2
class B(A):
def f(self, num):
return 7*self.f(num)
In the very last line, I want to refer to the parent class A with the “self.f(num)” command, not the method itself in B which would create an infinite recursion. Thank you in advance.
If you know you want to use A you can also explicitly refer to A in this way:
remember you have to explicitly give the self argument to the member function A.f()