0
How is length 3? What is the working and process i.e how is code getting executed on a line by line basis?
a=[1,2] d=a a.append(7) print(len(d)) The output i.e length of d is 3, even though I have appended 7 to a, not d. How? What is the process of execution on a line by line basis.
1 ответ
+ 9
d=a
Means you passed a as reference not as copy.
So changes made in a also affect d .
If you don't want it use
d=a.copy()