python将两个数组合并成一个数组的两种方法的代码

时间:2023-12-10 12:54:50

内容过程中,把写内容过程中常用的内容收藏起来,下面的资料是关于python将两个数组合并成一个数组的两种方法的内容,希望能对小伙伴们有帮助。
c1 = ["Red","Green","Blue"]
c2 = ["Orange","Yellow","Indigo"]
c1.extend(c2)

assert c1 == ["Red","Green","Blue","Orange","Yellow","Indigo"]

下面使用+号操作符

c1 = ["Red","Green","Blue"]
c2 = ["Orange","Yellow","Indigo"]
c3 = c1 + c2

assert c3 == ["Red","Green","Blue","Orange","Yellow","Indigo"]