Python 官方文档:入门教程 => 点击学习
matrix0 = [[1, 2], [3, 3], [2, 1]] print 'matrix0:', matrix0 matrix1 = [[1 for i in range(2)] for i in range(3)] prin
matrix0 = [[1, 2], [3, 3], [2, 1]]
print 'matrix0:', matrix0
matrix1 = [[1 for i in range(2)] for i in range(3)]
print 'matrix1:', matrix1
matrix2 = [[0 for i in range(2)] for i in range(3)]
print 'matrix2:', matrix2
for i in range(3):
for j in range(2):
matrix2[i][j] = matrix0[i][j] + matrix1[i][j]
print 'matrix2:', matrix2
print('Good bye')
运行结果:
matrix0: [[1, 2], [3, 3], [2, 1]]
matrix1: [[1, 1], [1, 1], [1, 1]]
matrix2: [[0, 0], [0, 0], [0, 0]]
matrix2: [[2, 3], [4, 4], [3, 2]]
Good bye
--结束END--
本文标题: Python双层for循环
本文链接: https://lsjlt.com/news/186895.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0