慕前端0137584
2021-03-08 14:55
d=['Alice','Bob','Candy','David','Ellena']
l=['Gen','Phoebe','Zeo']
d.append(l)
print(d) ==>['Alice', 'Bob', 'Candy', 'David', 'Ellena', ['Gen', 'Phoebe', 'Zeo']]
用extend,extend是将两个list合并成一个list。append()是将你传入的参数看做一个元素,拼到 上一个list中
d=['Alice','Bob','Candy','David','Ellena']
l=['Gen','Phoebe','Zeo']
d.extend(l)
print(d)
d=['Alice','Bob','Candy','David','Ellena']
l=['Gen','Phoebe','Zeo']
for x in l:
d.append(x)
print(d)
Python3 入门教程(新版)
154167 学习 · 1075 问题
相似问题