Method 1: Using Nested Loops.
matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] # Using nested loops to print the matrix for row in matrix: for element in row: print(element, end=" ") print() # Move to the next line after printing a row
1 2 3
4 5 6
7 8 9
Method 2: Using List Comprehension.
matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] # Using list comprehension to print the matrix [print(*row) for row in matrix]
1 2 3
4 5 6
7 8 9 Method 3: Using NumPy Library.
import numpy as np matrix = np.array([ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]) # Printing the NumPy matrix print(matrix)
1 2 3
4 5 6
7 8 9





