扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

python中两个列表合在一起的方法是什么

扬州沐宇科技
2023-10-18 09:53:46
python

在Python中,可以使用"+"运算符将两个列表合并在一起。例如:

list1 = [1, 2, 3]
list2 = [4, 5, 6]
merged_list = list1 + list2
print(merged_list)

输出:

[1, 2, 3, 4, 5, 6]

另外,还可以使用extend()方法将一个列表的元素添加到另一个列表中。例如:

list1 = [1, 2, 3]
list2 = [4, 5, 6]
list1.extend(list2)
print(list1)

输出:

[1, 2, 3, 4, 5, 6]

扫码添加客服微信