Tutorials

Python 3 Tutorial

All Tutorials Learning Tools Login

Python 3 Tutorial · Chapter 19 of 22

Python 2D Lists

Use nested lists for rows and columns.

A 2D list is a list of lists. Outer index is the row; inner index is the column.

Nested loops print tables cleanly.

2D list sample Try it Yourself »
matrix = [[1, 2, 3], [4, 5, 6]]
for row in matrix:
    for value in row:
        print(value, end=" ")
    print()

Classroom Tips

  • Keep row lengths consistent in beginner labs.