I'm confused about how to create a python3 two-dimensional array list.
a=[0]*3 for i in range(4)]
b = [[0]*3]*4
for i in range (4):
for jin range(3):
a[i][j]=f'{i}_{j}'
b[i][j]=f'{i}_{j}'
Due to the difference in the way two-dimensional array is created, the results will be different as follows:
For list inclusion of a,
[['0_0', '0_1', '0_2',] ,
['1_0', '1_1', '1_2'],
['2_0', '2_1', '2_2'],
['3_0', '3_1', '3_2']]
Multiply the list of b by
[['3_0', '3_1', '3_2',] ,
['3_0', '3_1', '3_2'],
['3_0', '3_1', '3_2'],
['3_0', '3_1', '3_2']]
How do I understand the difference in output?
python python3
a is another list and b is the same (as metropolis, payaneco wrote in the comments).
The figure below shows for easy visibility.
857 Uncaught (inpromise) Error on Electron: An object could not be cloned
1238 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
762 Error in x, y, and format string must not be None
772 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2025 OneMinuteCode. All rights reserved.