Python列表类型list合并有哪些方法?
在Python编程语言中,有各种数据类型,比如字符串、列表、集合、有序集合、数组等等,对于刚接触Python的同学来说,可能会有些陌生和畏惧,本篇文章将为大家带来Python中list合并的4种方式,如果你还不太清楚,请看下文:
方法一、直接使用"+"号合并列表
aList=[3,4,5];
bList=['abc','Python'];
cList=aList+bList;
dList=bList+aList;print(cList);print(dList);
//输出为//[3,4,5,'abc','Python'];//['abc','Python',3,4,5]
方法二、使用extend方法
aList=[1,3,4];
bList=['abc','Python_study'];
aList.extend(bList);print(aList);
//输出为//[1,3,4,'abc','Python_study'];
方法三、使用切片
aList=[1,2,3];
bList=['aaa','Python_class'];
aList[len(aList):len(aList)]=bList;print(aList);
//输出为//[1,2,3,'aaa','Python_class'];
方法四、使用append方法
aList=[1,2,3];
bList=['aaa','Python_class'];
aList.append(bList);print(aList);
//输出为//[1,2,3,['aaa','Python_class']];

相关推荐HOT
更多>>
什么是Python的多进程和多线程?
学Python的朋友听说过进程和线程吗?其实,不仅是Python,学习技术也涉及进程和线程。后面朋友们还可能接触到各种线程锁。那么什么是Python的多...详情>>
2023-11-05 22:00:19
深圳靠谱的python培训机构有哪些?
Python是一门简单又不简约的语言。阅读好的Python程序感觉就像阅读英语。而如今python也越来越火,这也吸引了很多人进行Python学习。不过python...详情>>
2023-11-05 19:15:02
Python的应用领域都有哪些?
1、Python在系统编程中的应用Python语言在操作系统的内置接口,被称为Shell工具。Python程序可以搜索文件和目录树、可以运行其他的应有程序或是...详情>>
2023-11-05 18:48:45
linux命令连接服务器?
linux下用ftp命令连接到ftp服务器应该如何查看服务器上的目录文件数_百...您登陆到ftp上用ls |wc -l就可以,直接列出有多少个文件目录,我记得...详情>>
2023-10-29 23:45:52热门推荐
技术干货






