Tutorials

Python 3 Tutorial

All Tutorials Learning Tools Login

Python 3 Tutorial · Chapter 20 of 22

Python 3D Lists

Organize layers, rows, and columns.

A 3D list adds a layer dimension on top of rows and columns.

Triple nested loops visit every value.

3D list sample Try it Yourself »
cube = [
    [[1, 2, 3], [4, 5, 6]],
    [[7, 8, 9], [10, 11, 12]],
]
for layer_index, layer in enumerate(cube):
    print(f"Layer {layer_index + 1}:")
    for row in layer:
        for value in row:
            print(value, end=" ")
        print()
    print()

Classroom Tips

  • Name indexes clearly: layer, row, col.