python快速生成一个二维数组
m=2
n=3
memo_01 = [[1] * m for i in range(n) ]
memo_02 = [[1]*m]*n
print("memo_01:{},memo_02:{},".format(memo_01,memo_02)) # memo_01:[[1, 1], [1, 1], [1, 1]],memo_02:[[1, 1], [1, 1], [1, 1]]
memo_01[0][0]=2 # 这一种创建方式类似于深拷贝
memo_02[0][0]=2 # 这一种创建方式类似浅拷贝
print("memo_01:{},memo_02:{},".format(memo_01,memo_02)) # memo_01:[[2, 1], [1, 1], [1, 1]],memo_02:[[2, 1], [2, 1], [2, 1]]
相关推荐
bizercsdn 2020-04-22
sdwylry 2020-02-20
pythonpycharm 2019-05-31
cairencong 2018-06-05
JasonYeung 2018-04-13
liusarazhang 2018-04-13
逍遥友 2018-04-03
没有学不好的技术 2018-04-03
assastor 2018-04-03
waiwaiLILI 2010-03-17
xinhao 2010-03-16
farewellpoem 2010-03-05
pymanhall 2017-11-07
DCXabc 2017-09-22
Python探路者 2019-04-19
Pythonandme 2019-03-02
pythoncream 2019-01-28