如何在python中将2 for循环插入到print函数中

时间:2017-06-24 09:16:08

标签: python loops for-loop

我有使用problam将2个循环插入到我的打印功能中, 我试图打印以下内容:

[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20],
[0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30], 
[0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40], 
[0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50], 
[0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60],
[0, 7, 14, 21, 28, 35, 42, 49, 56, 63, 70],
[0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80],
[0, 9, 18, 27, 36, 45, 54, 63, 72, 81, 90],
[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]]

在1个打印行中!

我的尝试: print ( for y in range(11) [x*y for x in range(11)] )

如果有人可以指导我,它会帮助我很多

1 个答案:

答案 0 :(得分:0)

print([[x * y for x in range(11)] for y in range(11)])