python学习===复制list

"""将一个列表的数据复制到另一个列表中。"""

"""
使用[:]

"""

a = [1,2,3]
b = a[:]
print b       # 将a的数据赋值给b 当a的数值发生改变时b不变
[1, 2, 3]
a = [1,2,3]
b = a
print b       # 将a的地址赋值给b 当a的数值发生改变时b随之改变
[1, 2, 3]
a = [1,2,3]
b = a[:]
print b
a[0] = 0
print a        # 将a的数据赋值给b 当a的数值发生改变时b不变
print b
[1, 2, 3]
[0, 2, 3]
[1, 2, 3]
a = [1,2,3]
b = a
print b
a[0] = 0
print a         # 将a的地址赋值给b 当a的数值发生改变时b随之改变
print b

 

posted @ 2017-08-03 15:58  AAA五金批发王建军  阅读(273)  评论(0编辑  收藏  举报