如何在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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 17:53:52  来源:igfitidea点击:

How do I merge arrays in python?

pythonarrays

提问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]