题目:将一个列表的数据复制到另一个列表中。
方法一:
# -*- coding:utf-8 -*-
a = [1,2,3]
b = a[:]
print b
方法二:
# -*- coding:utf-8 -*-
import copy
a = [1,2,3]
b = copy.copy(a)
print b
方法三:
# -*- coding:utf-8 -*-
a = [1,2,3]
b = []
for i in range(len(a)):
b.append(a[i])
print b
方法四:
# -*- coding:utf-8 -*-
a = [1,2,3]
b = [i for i in a]
print b
网友评论