I’m using python 3.9.5. My code is
a = [[0,1],[1,2]]
b = a
b[1] = [4,5]
Both of the variables are [[0,1],[4,5]] now. But i don’t want to apply changes to variable a. What should i do? I’ve tried to use the c = b statement but it didn’t help.
CodePudding user response:
There is a very useful function that python has for arrays. You can use a.copy()
to produce an exact copy of the array. I believe b = a.copy()
would solve your problem.