How to Use a Nested Loop in Python


In this example, we will learn how to use a nested loop in Python.

Source Code

num = [1, 2, 3]
str = 'abc'
for x in num:
    for y in str:
        print(x, y)

Output:

1 a
1 b
1 c
2 a
2 b
2 c
3 a
3 b
3 c
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments