python 定义二维数组

1. myList = [([0] * n) for i in range(m)],n是列,m是行

>>> array=[([0]*3) for i in range(4)]
>>> for i in range(4):
...     for j in range(3):
...             print array[i][j],
...     print "\n"
... 
0 0 0 

0 0 0 

0 0 0 

0 0 0 

>>> array[0][1]=1
>>> for i in range(4):
...     for j in range(3):
...             print array[i][j],
...     print "\n"
... 
0 1 0 

0 0 0 

0 0 0 

0 0 0 

>>> 

2.array = [ [ 0 for i in range(n)] for i in range(m)],n是列,m是行

>>> array=[[0 for i in range(3)] for i in range(4)]
>>> for i in range(4):
...     for j in range(3):
...             print array[i][j],
...     print "\n"
... 
0 0 0 

0 0 0 

0 0 0 

0 0 0 

>>> array[0][1]=1
>>> for i in range(4):
...     for j in range(3):
...             print array[i][j],
...     print "\n"
... 
0 1 0 

0 0 0 

0 0 0 

0 0 0 

>>> 
posted @ 2017-09-07 21:13  xushukui  阅读(4277)  评论(0编辑  收藏  举报