Output question. | SoloLearn: Learn to code for FREE!


Output question.

Why is the output of the following code = [1,[2,5]]? a= [1,[2,3]] b= a[:] a[0] = 3 a[1][1] = 5 print(b)

9/1/2019 6:15:26 PM


4 Answers

New Answer


b = a[:] copies all indexes to b, since a[1] is a list the refernce to that list get copied. when you now edit a[1] the change is in b too. you perhaps should use: import copy b = copy.deepcopy(a)


Sorry about that, that was my first question, I didn't think about that, my bad


Please mention the language in Relevant Tags rather than a sentence or question 'why on the following scrip,'. Proper use of tags helps improve search feature quality 👍


I understand, just reminding you in case you forget, no problem buddy 👍