|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
代码如下:
def New_arr1(row1 , initial_value):
Arr = []
for i in range(row1):
arr_i = initial_value
Arr.append(arr_i)
return Arr
def Cache_list(n , m ,sort_k_list):
cache1 = New_arr1(n, [])
print(cache1)
cache2 = []
for i in range(n):
cache2.append([])
print(cache2)
cache1[3].append(8)
print(cache1)
cache2[3].append(8)
print(cache2)
我定义了一个创建空list的函数,在函数Cache——list中,一个是调用NEW函数进行创建cache1,一个是直接用相同方法创建cache2
执行如下
[[], [], [], [], [], [], [], [], [], []] 这里是cache1
[[], [], [], [], [], [], [], [], [], []] 这里是cache2
[[8], [8], [8], [8], [8], [8], [8], [8], [8], [8]] 当cache1[3].append(8) 时,整个cache1全部加入了8
[[], [], [], [8], [], [], [], [], [], []] 当cache2[3].append(8) 时,正常执行
请问:当cache1[3].append(8) 时,整个cache1全部加入了8
这到底是为什么!!!!
求解,谢谢各位鱼油 |
|