python 基础之深浅拷贝
深浅拷贝
1 2 3 4 | s = [[ 1 , 2 ], 'fgfgf' , 'cx' ] s3 = s.copy() print (s) print (s3) |
测试
1 2 3 4 5 | D:\python\python.exe D: / untitled / dir / for .py [[ 1 , 2 ], 'fgfgf' , 'cx' ] [[ 1 , 2 ], 'fgfgf' , 'cx' ] Process finished with exit code 0 |
浅拷贝之修改
1 2 3 4 5 6 | s = [[ 1 , 2 ], 'fgfgf' , 'cx' ] s3 = s.copy() print (s3) s3[ 1 ] = 'chhgghg' print (s) print (s3) |
测试
1 2 3 4 5 6 | D:\python\python.exe D: / untitled / dir / for .py [[ 1 , 2 ], 'fgfgf' , 'cx' ] [[ 1 , 2 ], 'fgfgf' , 'cx' ] [[ 1 , 2 ], 'chhgghg' , 'cx' ] Process finished with exit code 0 |
浅拷贝之修改列表
1 2 3 4 5 6 | s = [[ 1 , 2 ], 'fgfgf' , 'cx' ] s3 = s.copy() print (s3) s3[ 0 ][ 1 ] = 'chhgghg' print (s) print (s3) |
测试
1 2 3 4 5 6 | D:\python\python.exe D: / untitled / dir / for .py [[ 1 , 2 ], 'fgfgf' , 'cx' ] [[ 1 , 'chhgghg' ], 'fgfgf' , 'cx' ] [[ 1 , 'chhgghg' ], 'fgfgf' , 'cx' ] Process finished with exit code 0 |
浅拷贝是复制一层
深拷贝
1 2 3 4 5 6 7 | haha = [ 'cx' , 123 ,[ 15000 , 9000 ]] wit = copy.deepcopy(haha) wit[ 0 ] = 'cd' wit[ 1 ] = 6666 wit[ 2 ][ 1 ] = 1999 print (wit) print (haha) |
测试
1 2 3 4 5 6 | D:\python\python.exe D: / untitled / dir / for .py [[ 1 , 2 ], 'fgfgf' , 'cx' ] [[ 1 , 'chhgghg' ], 'fgfgf' , 'cx' ] [[ 1 , 'chhgghg' ], 'fgfgf' , 'cx' ] [ 'cd' , 6666 , [ 15000 , 1999 ]] [ 'cx' , 123 , [ 15000 , 9000 ]] |
草都可以从石头缝隙中长出来更可况你呢
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏