Editor

Predict the Output

Intermediate · Predict the output · from Nested Loops: Patterns, Performance, and When to Avoid Them

From the lesson: Nested Loops: Patterns, Performance, and When to Avoid Them

Think about a spreadsheet. It has rows and columns. To read every cell, you go through each row, and for each row, you go through each column. That's two loops - one inside the other. That's a nested loop.

Read the lesson

Without running the code, predict what it will print. Count the total number of lines in the output. Then run it to check.

for i in range(3):
for j in range(2):
print(f'{i}-{j}')

More Nested Loops exercises

All Python exercises · 50 practice problems · Control Flow quiz