【Python】拷贝&列表
2021-05-28 15:04
标签:bsp 对象 end odi app color import 数组 usr 最后的输出结果为: 【Python】拷贝&列表 标签:bsp 对象 end odi app color import 数组 usr 原文地址:https://www.cnblogs.com/LeeCookies/p/14782344.html 1 #!/usr/bin/python
2 # -*-coding:utf-8 -*-
3
4 import copy
5 a = [1, 2, 3, 4, [‘a‘, ‘b‘]] #原始对象
6
7 b = a #赋值,传对象的引用
8 c = copy.copy(a) #对象拷贝,浅拷贝
9 d = copy.deepcopy(a) #对象拷贝,深拷贝
10
11 a.append(5) #修改对象a
12 a[4].append(‘c‘) #修改对象a中的[‘a‘, ‘b‘]数组对象
13
14 print( ‘a = ‘, a )
15 print( ‘b = ‘, b )
16 print( ‘c = ‘, c )
17 print( ‘d = ‘, d )
1 (‘a = ‘, [1, 2, 3, 4, [‘a‘, ‘b‘, ‘c‘], 5])
2 (‘b = ‘, [1, 2, 3, 4, [‘a‘, ‘b‘, ‘c‘], 5])
3 (‘c = ‘, [1, 2, 3, 4, [‘a‘, ‘b‘, ‘c‘]])
4 (‘d = ‘, [1, 2, 3, 4, [‘a‘, ‘b‘]])
上一篇:centos安装java8
下一篇:java类实例化的4种方式