Python Fundamentals · Control Flow
A loop inside a loop: for every row, the inner loop runs all the way through. Build a 3 × 3 times table.
grid = []
for row in range(1, 4):
line = []
for col in range(1, 4):
line.append(row * col)
grid.append(line)
print(grid)row is created with the value 1.col is created with the value 1.col changes from 1 to 2.line points to.col changes from 2 to 3.line points to.for col in range(1, 4).line now points to a different list: [].col changes from 3 to 1.line points to.col changes from 1 to 2.line points to.col changes from 2 to 3.line points to.for col in range(1, 4).grid points to.row changes from 2 to 3.line now points to a different list: [].col changes from 3 to 1.line points to.col changes from 1 to 2.line points to.col changes from 2 to 3.line points to.for col in range(1, 4).grid points to.for row in range(1, 4).