How to iterate through the rows of a two-dimensional array in Python?

In Python, nested loops can be used to iterate through the rows of a two-dimensional array. For example, for a two-dimensional array arr, the following code can be used to iterate through each row:

arr = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

for row in arr:
    print(row)

The code above will print out each line in the array arr, for example:

[1, 2, 3]
[4, 5, 6]
[7, 8, 9]

If you need to access each element in every row, you can loop through them again within an inner loop, for example:

for row in arr:
    for element in row:
        print(element)

The code above will display each element in the array arr, for example:

1
2
3
4
5
6
7
8
9
bannerAds