1 #方法一:这是最先想到的 2 s = [[1,2,3], [4,5,6], [7,8,9]] 3 n = int(input()) 4 5 r = [] 6 for i in s: 7 a = [] #这个很重要,每次要清空 8 for j in i: 9 a.append(j * n) 10 r.append(a) 11 12 print(r) 13 14 15 16 17 18 19 #方法二:参考网友解法修改的 20 s = [[1,2,3], [4,5,6], [7,8,9]] 21 n = int(input()) 22 23 print("原始数据:", s) 24 for i in range(len(s)): 25 for j in range(len(s[0])): 26 s[i][j] *= n 27 28 print(s)
标签:python,矩阵,len,int,相乘,print,input,append From: https://www.cnblogs.com/bravesunforever/p/17627031.html