I'm trying to understand what is the main difference between the 2 versions as well as how do i access the a1? Any help or resources is greatly appreciated
class a:
def __init__(self,a1,a2):
self.a1 = a1
self.a2 = a2
def get_a1(self):
return self.a1
def get_a2(self):
return self.a2
class b(a):
def __inti__list_ab(self,list_ab):
self.list_ab =[]
def __init__(self,a1,a2,b1):
super().__init__(a1,a2)
self.b1 = b1
def add_ab(newab):
b.list_ab.append(newab)
boy = b("Kel","AL","Jon")
girl = b("Jill","Mary","Ann")
b.add_ab(boy)
Version 2
class b(a):
list_ab = []
def __init__(self,a1,a2,b1):
super().__init__(a1,a2)
self.b1 = b1
def add_ab(newab):
b.list_ab.append(newab)
question from:
https://stackoverflow.com/questions/65839583/noob-trying-to-understand-inheritance-and-list-for-objects 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…