how to use 2d arrays in python code example
Example 1: create a 2d array in python
def build_matrix(rows, cols):
matrix = []
for r in range(0, rows):
matrix.append([0 for c in range(0, cols)])
return matrix
if __name__ == '__main__':
build_matrix(6, 10)
Example 2: 2D array python
# 2D arrays in python can be used to create rudimentary games
array_2d = [['row0, column0'], ['row0, column1'], ['row0, column2'],
['row1, column0'], ['row1, column1'], ['row1, column2'],
['row2, column0'], ['row2, column1'], ['row2, column2']]