I came across a piece of python code, requiring me to give the output. The code goes as follows:
a = [1, 2]
b = [a, 3]
c = b[:]
a[0] = 7
b[1] = 8
print c
I thought the output to be [[7, 2], 8] since i have the reference to the a in b, and consequently, c had the reference to b
But the output came out to be [[7, 2], 3]
What am I missing here?
c = bc = b[:]creates a (flat) copy ofbasc. Changes inbare not reflected toc.c = b[:]is a shallow copybare not reflected inc, how come the changes inaare getting reflected inc?