当前位置:   article > 正文

Python将两个列表合并成一个列表_python两个列表合并成一个列表

python两个列表合并成一个列表

Python将两个列表/数组合并成一个列表/数组

  1. extend方法
>>>c1 = ["Red","Green","Blue"]
>>>c2 = ["Orange","Yellow","Indigo"]
>>>c1.extend(c2)
>>>c1 #["Red","Green","Blue","Orange","Yellow","Indigo"] 
  • 1
  • 2
  • 3
  • 4
  1. 直接相加
>>>c1 = ["Red","Green","Blue"]
>>>c2 = ["Orange","Yellow","Indigo"]
>>>c3 = c1 + c2
>>>c3 #  ["Red","Green","Blue","Orange","Yellow","Indigo"]
  • 1
  • 2
  • 3
  • 4
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号