+ 1
How does nested for loop work, 2,3,4
4 Réponses
+ 1
for x in list1:
for y in list2:
print(str(x) +str(y)
+ 6
Nested for loop means, that inside an 'outer' for loop, an 'inner' for loop is running. Sample:
l1 = ['a','b','c']
l2 = [1, 2, 3]
for outer in l1: # outer loop
for inner in l2: # inner loop
print(f'{outer}{inner}', end= ', ')
# output: a1, a2, a3, b1, b2, b3, c1, c2, c3,
As you can see the first outer value is taken, and then a complete iteration on the inner loop is done. Then next outer value and again a complete iteration on inner loop is done, and so on...
+ 2
could u clarify what u mean please?
+ 1
If you need help, you can post the code you're struggling with! https://www.sololearn.com/post/75089/?ref=app