是否可以通过使用我在后面的类中定义的方法从类B调用它来组合这两个列表,以便我可能得到的结果是1,2,3,4,5,6?
class A(object):
def __init__(self):
self.container = [1,2,3]
class B(A):
def __init__(self):
self.ano_containter = [4,5,6]
def join_lists(self):
for x in self.ano_containter:
print(x)
答案 0 :(得分:3)
为什么不将它们连接起来?
class B(A):
def __init__(self):
super(A, self).__init__() # make sure you initialize your parent class properly
self.ano_container = [4,5,6]
def join_lists(self):
return self.container + self.ano_container # or print them if you wish