标签:导致 int pre range print 一个 time class mes
L=[[0]*n]*m
方式初始化L=[[0]*3]*2
print("初始的:",L)
#赋值
for i in range(2):
for j in range(3):
L[i][j]=i+j
print("赋值后:",L)
>>>初始的:
[[0,0,0],[0,0,0]]
>>>赋值后:
[[1,2,3],[1,2,3]]
L=[[0 for _ in range(3)] for _ in range(2)]
方式初始化L=[[0 for _ in range(3)] for _ in range(2)]
print("初始的:",L)
#赋值
for i in range(2):
for j in range(3):
L[i][j]=i+j
print("赋值后:",L)
>>>初始的:
[[0,0,0],[0,0,0]]
>>>赋值后:
[[0,1,2],[1,2,3]]
标签:导致 int pre range print 一个 time class mes
原文地址:https://www.cnblogs.com/brilliantM/p/14816376.html