Python 2D Array Assignment Guide
In Python, nested lists can be used to represent a two-dimensional array, and values can be assigned through indexing. For example, to create a 3×3 two-dimensional array and assign a value to one of the elements, you can do the following:
# 创建一个3x3的二维数组
array = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
# 给数组中的某个元素赋值
array[1][1] = 1
# 打印数组
for row in array:
print(row)
The output result is:
[0, 0, 0]
[0, 1, 0]
[0, 0, 0]
It is convenient to assign values to two-dimensional arrays using this method.