发现一件有意思的事情,直接上代码说话。
(1)代码1
len_0=8
data=[]
data_temp=[]
for i in range(0,6,1):
data_temp.clear()
for j in range(len_0):
aa=i*len_0+j
data_temp.append(aa)
data.append(data_temp)
print(data_temp)
print(len(data))for dat in data:
print(dat)
运行结果是:
[0, 1, 2, 3, 4, 5, 6, 7]
[8, 9, 10, 11, 12, 13, 14, 15]
[16, 17, 18, 19, 20, 21, 22, 23]
[24, 25, 26, 27, 28, 29, 30, 31]
[32, 33, 34, 35, 36, 37, 38, 39]
[40, 41, 42, 43, 44, 45, 46, 47]
6
[40, 41, 42, 43, 44, 45, 46, 47]
[40, 41, 42, 43, 44, 45, 46, 47]
[40, 41, 42, 43, 44, 45, 46, 47]
[40, 41, 42, 43, 44, 45, 46, 47]
[40, 41, 42, 43, 44, 45, 46, 47]
[40, 41, 42, 43, 44, 45, 46, 47]
(2)代码2
len_0=8
data=[]
for i in range(0,6,1):
data_temp=[]
data_temp.clear()
for j in range(len_0):
aa=i*len_0+j
data_temp.append(aa)
data.append(data_temp)
print(data_temp)
print(len(data))for dat in data:
print(dat)
运行结果是:
[0, 1, 2, 3, 4, 5, 6, 7]
[8, 9, 10, 11, 12, 13, 14, 15]
[16, 17, 18, 19, 20, 21, 22, 23]
[24, 25, 26, 27, 28, 29, 30, 31]
[32, 33, 34, 35, 36, 37, 38, 39]
[40, 41, 42, 43, 44, 45, 46, 47]
6
[0, 1, 2, 3, 4, 5, 6, 7]
[8, 9, 10, 11, 12, 13, 14, 15]
[16, 17, 18, 19, 20, 21, 22, 23]
[24, 25, 26, 27, 28, 29, 30, 31]
[32, 33, 34, 35, 36, 37, 38, 39]
[40, 41, 42, 43, 44, 45, 46, 47]
只是移动了data_temp的位置,改变的却是链表data的结果。代码1链表data的运行结果实在有点难以理解。