美文网首页工作生活
python3合并list,list添加元素

python3合并list,list添加元素

作者: 哪个鹿 | 来源:发表于2019-12-19 18:45 被阅读0次
    list1 = [1,2,3,'d','wsdftgyhuj']
    list2 = [7,8,8,9]
    list1.append(list2)
    print(list1)
    ==>[1, 2, 3, 'd', 'wsdftgyhuj', [7, 8, 8, 9]]
    
    list1 = [1,2,3,'d','wsdftgyhuj']
    list2 = [7,8,8,9]
    list1.extend(list2)
    print(list1)
    ==>[1, 2, 3, 'd', 'wsdftgyhuj', 7, 8, 8, 9]
    
    list1 = [1,2,3,7,9,'d','wsdftgyhuj']
    list2 = [7,8,8,9]
    print(list1+list2)
    ==>[1, 2, 3, 7, 9, 'd', 'wsdftgyhuj', 7, 8, 8, 9]
    
    list1 = [1,2,3,7,9,'d','wsdftgyhuj']
    list2 = [''] * 4
    list1.extend(list2)
    print(list1)
    ==>[1, 2, 3, 7, 9, 'd', 'wsdftgyhuj', '', '', '', '']
    

    相关文章

      网友评论

        本文标题:python3合并list,list添加元素

        本文链接:https://www.haomeiwen.com/subject/jwtthctx.html