码迷,mamicode.com
首页 > 其他好文 > 详细

2-7

时间:2019-12-11 13:02:24      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:copy   style   print   import   方法   int   pre   切片   code   

2-7

#列表的copy方法
names = [a, b, c, d, e]
names2 = names.copy()
print(names)
print(names2)

names[2] = CC
print(names)
print(names2)

#浅copy
names = [a, b, [1, 2, 3], d]
names2 = names.copy()
names[1] = BB
names[2][1] = 22
print(names)
print(names2)


#直接copy
names = [a, b, [1, 2, 3], d]
names2 = names
names[1] = BB
names[2][1] = 22
print(names)
print(names2)


#完全copy一份列表
import copy

#浅copy, =names.copy()
names = [a, b, [1, 2, 3], d]
names2 = copy.copy(names)
names[1] = BB
names[2][1] = 22
print(names)
print(names2)

#深copy
names = [a, b, [1, 2, 3], d]
names2 = copy.deepcopy(names)
names[1] = BB
names[2][1] = 22
print(names)
print(names2)



#列表循环
for i in names:
    print(i)


#切片步长
names = [a, b, c, d, e, f, g, h]
print(names)
print(names[0:-1:2])
print(names[::2])

 

2-7

标签:copy   style   print   import   方法   int   pre   切片   code   

原文地址:https://www.cnblogs.com/python-abc/p/12021751.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!