如何在python中合并数组?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46866105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I merge arrays in python?
提问by Yur3k
I have 2 arrays, for example: [1, 2, 3] and [4, 5, 6] How do i merge them into 1 big array?: [1, 2, 3, 4, 5, 6] not [[1, 2, 3], [4, 5, 6]]
我有 2 个数组,例如: [1, 2, 3] 和 [4, 5, 6] 我如何将它们合并成 1 个大数组?: [1, 2, 3, 4, 5, 6] 不是 [[ 1, 2, 3], [4, 5, 6]]
回答by Sreeram TP
+
operator can be used to merge two lists.
+
运算符可用于合并两个列表。
data1 = [1, 2, 3]
data2 = [4, 5, 6]
data = data1 + data2
print(data)
# output : [1, 2, 3, 4, 5, 6]
Lists can be merged like this in python.
列表可以在python中像这样合并。
回答by gsamaras
By using the +
operator, like this:
通过使用+
运算符,如下所示:
>>> [1, 2] + [3, 4]
[1, 2, 3, 4]