Apr-09-2021, 12:12 PM
Not homework but I'm a noob ;)
Outputs:
I can't understand why 'b after' isn't the same as 'a after'.
Cheers.
Quote:a = [[0,0,0],[0,0,0],[0,0,0]]
b = [[0] * 3] * 3
print(a == b)
print(' a =', a)
print(' b =', b)
a[0][0] = 1
b[0][0] = 1
print('a after =', a)
print('b after =', b)
Outputs:
Quote:True
a = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
b = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
a after = [[1, 0, 0], [0, 0, 0], [0, 0, 0]]
b after = [[1, 0, 0], [1, 0, 0], [1, 0, 0]]
I can't understand why 'b after' isn't the same as 'a after'.
Cheers.