python 两个list相加
时间: 2023-08-10 09:04:56 浏览: 57
可以使用"+"运算符将两个列表相加,这将返回一个新的列表,其中包含两个列表中的所有元素。例如:
```
list1 = [1, 2, 3]
list2 = [4, 5, 6]
new_list = list1 + list2
print(new_list)
```
输出结果为:
```
[1, 2, 3, 4, 5, 6]
```
相关问题
python 两个list数字相加
可以使用zip()函数来实现两个列表的数字相加。具体实现方式如下所示:
```
list1 = [1, 2, 3]
list2 = [4, 5, 6]
result = [x + y for x, y in zip(list1, list2)]
print(result)
```
输出结果为:
```
[5, 7, 9]
```
其中,zip()函数可以将两个列表中的元素一一对应起来,然后使用for循环遍历每一对元素,将它们相加并存储到新的列表中。
python两个列表相加
在Python中,可以使用"+"运算符将两个列表相加。这将会创建一个新的列表,其中包含了两个原始列表的所有元素。下面是一个示例:
```python
list1 = [1, 2, 3]
list2 = [4, 5, 6]
result = list1 + list2
print(result)
```
输出结果为:[1, 2, 3, 4, 5, 6]