救命
请问大佬如何创建一个二维列表?for i in range(88):
matrix.append([])
for j in range(88):
matrix.append(random.randint(0, 1024))
这个不是生成一行有88列的列表吗? 这个代码没有问题啊 这个是生成一行有88列,总共有88行的列表 楼主的代码是 OK 的,来一个列表推导式的
matrix = [for _ in range(88)] 很正常呀
Python 3.8.10 (tags/v3.8.10:3d8993a, May3 2021, 11:48:03) on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> import random
>>> matrix = []
>>> for i in range(88):
matrix.append([])
for j in range(88):
matrix.append(random.randint(0, 1024))
>>> len(matrix)
88
>>> len(matrix)
88
>>> 没问题啊
Python 3.11.0 (main, Oct 24 2022, 18:26:48) on win32
Type "help", "copyright", "credits" or "license()" for more information.
import random
matrix=[]
for i in range(88):
matrix.append([])
for j in range(88):
matrix.append(random.randint(0, 1024))
len(matrix)
88
len(matrix)
88
len(matrix)
88
matrix
[, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ]
页:
[1]