I need an insight into understanding the below code. The first print gives me output: 'a' whereas on changing the value of y[0][0]
to "p" it changes the value of y[0][0]
, y[1][0]
, y[2][0]
and y[3][0]
as well. I was expecting an output like [['p', 'b', 'c'], ['a', 'b', 'c'], ['a', 'b', 'c'], ['a', 'b', 'c']]
but instead got [['p', 'b', 'c'], ['p', 'b', 'c'], ['p', 'b', 'c'], ['p', 'b', 'c']]
x=["a","b","c"]
y = [x] * 4
# first print
print(y[0][0])
y[0][0] = "p"
# second print
print(y)