+ 2
Double loops inside list.
Please explain the output of this code: https://code.sololearn.com/c8pHPZxYUfi1/?ref=app
3 Respuestas
+ 4
You will get a list of lists.
You will get a list at each iteration with the values [a,b].
for a in range(0,2):
for b in range(0,2):
When a is 0, the inner loop executes and b is first 0 and then 1. So you get [0,0] and [0,1].
When a is 1, the inner loop again executes and b is first 0 and then 1. So you get [1,0] and [1,1].
+ 3
thats same as
for a in range(0,2):
for b in range(0,2):
x.append([a,b])
it goes
[0,0],[0,1],[1,0],[1,1]