Python for loop nesting

for i in range (0,5):
for j in range (0,5):

   print i, j

0 0
01
0 2
0 3
0 4
1 0
.
4 4
Why is this the result? isn"t it reasonable that the output of the first line is only 01234? Please explain it in detail. Thank you, thank you.

Apr.02,2021

nested loop is like this. When the outer loop icycle 0, the inner loop j from 0 to 4, the inner loop ends, then icycle 1, the inner layer 0 to 4, and so on, until icycle 4, the outer loop ends, a total of 4 times 4 for a total of 16 times.


first execute the outer loop, icycle 0, and then, in the case of icycle 0, execute the first pass inner loop, the value of j changes from 0 to 4
, and then icycle 1 executes the inner loop, and the value of j changes from 0 to 4
.
until icycle 5, exit the loop

Menu