+ 2
how the code works ?
n = 2 a = [[0] * n for i in range(n)] Output is --> [[0,0] , [0,0]] Please explain the output how it has come ?
1 RĂ©ponse
+ 1
a = [[0]*2 for i in range(2)]
[0]*2 = [0]+[0] = [0,0]
range(2) contains 2 numbers so [0,0] is used twice.
result is a list containing [0,0] twice.