python两个list[]相加的实现方法
作者:lexsaints 时间:2023-09-22 13:34:52
1、 利用操作符+
比如:
a = [1,2,3]
b = [4,5,6]
c = a+b
c的结果:[1,2,3,4,5,6]
2 利用extend
比如:
a = [1,2,3]
b = [4,5,6]
a.extend(b)
a的结果:[1,2,3,4,5,6]
结果是一样的,但是+号生成的是一个新的对象,而extend则是在原地的修改a对象。
另外注意:列表的append方法,是往列表中添加新元素
比如:
a = [1,2,3]
a.append(4) #后面跟的是元素类型
a的结果为:[1,2,3,4]
来源:https://blog.csdn.net/weixin_42350212/article/details/80628539
标签:python,列表,相加
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python pip安装模块提示错误解决方案
2022-03-07 02:26:27
![](https://img.aspxhome.com/file/2023/0/115450_0s.png)
ASP中CACHE缓存技术
2010-05-03 10:58:00
彻底弄懂Python中的回调函数(callback)
2021-02-26 23:51:57
![](https://img.aspxhome.com/file/2023/8/86148_0s.png)
Python 实现任意区域文字识别(OCR)操作
2021-04-23 03:52:37
![](https://img.aspxhome.com/file/2023/9/90499_0s.jpg)
如何在sae中设置django,让sae的工作环境跟本地python环境一致
2022-03-09 22:04:54
Javascript学习笔记之 函数篇(二) : this 的工作机制
2024-05-11 10:23:57
python求pi的方法
2023-04-04 06:49:17
python设置表格边框的具体方法
2023-11-13 08:08:48
![](https://img.aspxhome.com/file/2023/9/107099_0s.jpg)
asp如何在数据库中用好Transaction?
2010-06-22 21:07:00
字符,字节和编码
2009-12-09 15:59:00
![](https://img.aspxhome.com/file/UploadPic/200912/9/spacer-36s.gif)
python做接口测试的必要性
2022-06-09 00:05:41
如何利用Python打开txt格式的文件
2022-06-01 02:08:36
![](https://img.aspxhome.com/file/2023/3/99103_0s.png)
vue 开发一个按钮组件的示例代码
2024-04-30 10:27:40
带你轻松接触MySQL数据库的出错代码列表
2008-12-31 15:06:00
Python 文件操作实现代码
2023-07-12 08:30:59
Oracle 存储过程教程
2009-10-24 18:05:00
django如何自己创建一个中间件
2021-03-31 10:26:59
![](https://img.aspxhome.com/file/2023/5/71345_0s.png)
python通过paramiko复制远程文件及文件目录到本地
2023-02-07 06:03:28
FCKeditor 2.6.6在ASP中的安装及配置方法分享
2022-09-16 12:45:32
![](https://img.aspxhome.com/file/2023/6/70616_0s.bmp)
textarea 在IE和FF下换行无法正常显示的解决方法
2022-09-11 01:33:40