Tutorials

Python 3 Tutorial

All Tutorials Learning Tools Login

Python 3 Tutorial · Chapter 14 of 22

Python Nested For

Build patterns with nested loops.

An outer loop controls rows. An inner loop controls columns.

print(..., end=\" \") keeps values on the same line.

Nested for sample Try it Yourself »
for row in range(1, 6):
    for col in range(1, row + 1):
        print("*", end=" ")
    print()

Classroom Tips

  • Reset the line with a bare print() after each row.