更新原始数组会自动从原始数组定义另一个数组?

时间:2014-12-05 17:02:08

标签: python arrays slice

原始数组如:

arr = range(1,10)
print arr
# [1, 2, 3, 4, 5, 6, 7, 8, 9]

New将此原始数组提供给新变量xy

x = arr
y = arr
print arr, x, y
# [1, 2, 3, 4, 5, 6, 7, 8, 9] [1, 2, 3, 4, 5, 6, 7, 8, 9] [1, 2, 3, 4, 5, 6, 7, 8, 9]

更新原始数组,

arr.extend([10,11]) 
print arr, x, y  
# [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

或只更新x

x.extend([12, 13])
print x, arr
# [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

为什么?

0 个答案:

没有答案