python嵌套列表如何拷贝
python嵌套列表如何拷贝
1、拷贝说明
(1)若列表中嵌套列表,普通的方式(浅拷贝)将不再可用。采用list对象构造方式,可自行尝试上述介绍的其他方式
(2)当然,两层for语句可以用来复制嵌套列表。但是,如果嵌套层次太深,则需要太多for语句,这也取决于每个列表成员的数据类型。
2、实例
nums=[1,2,3,[4,5,6]]
copied_nums=list(nums)#list对象构造方式
copied_nums[3][1]=1010
print(f"numsaddr[0x{id(nums):x}],val:{nums}")
print(f"copied_numsaddr[0x{id(copied_nums):x}],val:{copied_nums}")
输出
numsaddr[0x29ec7dc5408],val:[1,2,3,[4,1010,6]]
copied_numsaddr[0x29ec8149b48],val:[1,2,3,[4,1010,6]]
以上就是python嵌套列表如何拷贝的方法,希望能对大家有所帮助,更多Python学习教程请关注IT培训机构:千锋教育。

猜你喜欢LIKE
相关推荐HOT
更多>>
python如何创建UDP服务器和客户端?
python如何创建UDP服务器和客户端?本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。1、创建UDP服务端的基本步骤(1)创建套接字并绑定...详情>>
2023-11-10 21:18:09
python条件判断分为哪几类?
python中条件判断分为哪几类?python中条件判断分为单项判断,双向判断和多向判断。1、单项判断单项判断最基本的就是if。stone=6ifstone>=6:prin...详情>>
2023-11-10 19:15:56
python多进程与多线程的简单区分
python多进程与多线程的简单区分1、区别多进程与多线程不同在于,多进程的每一个进程都有一份变量的拷贝,进程之间的操作互不影响。2、实例impo...详情>>
2023-11-10 16:04:13
python-=是什么意思
python中-=是什么意思当我们看到python中类似数学的算数符号时,如果是有加减的出现,就可以明确它们是赋值运算符的一种。本篇所要带来的是-=,...详情>>
2023-11-10 14:36:01热门推荐
技术干货






