'Trying to create a zero matrix of size m*n using lists but I'm unable to print the output in desired shape

M=[]
for j in range(3):
   l=[]
   for k in range(3):
       l.append(0)
   M.append(l)
print(M)

OUTPUT:[[0,0,0],[0,0,0],[0,0,0]]

But I want the output to be printed like this:
[[0, 0, 0],
[0, 0, 0],
[0, 0, 0]]



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source