I'm begginer of python. I can't understand inheritance and __init__()
.
class Num:
def __init__(self,num):
self.n1 = num
class Num2(Num):
def show(self):
print self.n1
mynumber = Num2(8)
mynumber.show()
RESULT: 8
This is OK. But I replace Num2
with
class Num2(Num):
def __init__(self,num):
self.n2 = num*2
def show(self):
print self.n1,self.n2
RESULT: Error. Num2 has no attribute "n1".
In this case, how can Num2
access n1
?