【发布时间】:2017-06-04 15:05:40
【问题描述】:
这是我的代码
for j in range(5,8):
for i in range(6):
print("[{}][{}]".format(i,j))
j-=1
这就是我得到的。在第一个完整循环之后,右侧的 j 值应该从 5 减少到 4。查看代码进一步解释
[0][5]
[1][4]
[2][3]
[3][2]
[4][1]
[5][0]
[0][6] # Here, I want the j value or 6 to decrement to 4 but it's incrementing
[1][5]
[2][4]
[3][3]
[4][2]
[5][1]
[0][7]
[1][6]
[2][5]
[3][4]
[4][3]
[5][2]
这就是我想要的
[0][5]
[1][4]
[2][3]
[3][2]
[4][1]
[5][0]
[0][4] # Here, I want the j value to decrement to 4
[1][3]
[2][2]
[3][1]
[4][0]
[0][3]
[1][2]
[2][1]
[3][0]
【问题讨论】:
-
for j in range(5, 8)应该是什么意思?
标签: python python-3.x loops for-loop nested-loops