方法一:+
a=[1,2,3]
b=[4,5,6]
a=a+b
打印结果: [1, 2, 3, 4, 5, 6]
方法二:extend
c=[1,2,3]
d=[4,5,6]
c.extend(d)
打印结果:[1, 2, 3, 4, 5, 6]
使用append的时候要注意了。
方法三:append
d=[1,2,3]
e=[4,5,6]
d.append(e)
打印结果:[1, 2, 3, [4, 5, 6]]
f = [1,2,3]
g = [4,5,6]
mergedlist =[]
for elem in f:
mergedlist.append(elem)
for elem in g:
mergedlist.append(elem)
print mergedlist
打印结果:[1, 2, 3, 4, 5, 6]