问答详情
源自:5-5 Python向list添加新的元素

可以在list中插入list吗

names1=['Alice','Bob','Candy','David','Ellena']

names2=['Gen','Phoebe','Zero']

names1.append(names2)

print(names1)

这样输出结果是:

['Alice','Bob','Candy','David','Ellena',['Gen','Phoebe','Zero']]

怎么样可以去掉输出结果中的[]?


提问者:慕妹221902 2020-09-24 06:19

个回答

  • 真实如烟
    2020-09-24 10:31:18
    已采纳

    names1=['Alice','Bob','Candy','David','Ellena']


    names2=['Gen','Phoebe','Zero']


    for item in names2:

        names1.append(item)


    print(names1)


  • weixin_慕设计6077655
    2020-10-25 12:51:47

    L1=['Alice', 'Bob', 'Candy', 'David', 'Ellena']

    L2=[89,67,29,48,3]

    n=1

    for item in L2:

    L1.insert(n,item)

    n+=2

    print(L1)

    还可以错位插入