Python - After a variable is assigned to another variable, under what condition do we assume the concept of shallow / deep copy?
I'm comparing three chunks of code: Case 1: ====== s = "string" x = s s= s+"s" print(s) #outputs strings print(x) #outputs string --> would x be a deep copy of s because concatenation was involved? Case 2: ====== c = [4,5,6] d = c c = c + ["KKK"] print(c) #outputs [4, 5, 6, 'KKK'] print(d) #outputs [4, 5, 6] --> would d be a deep copy of c because appending was involved? Case 3: ====== a = [1,2,3] b = a a[0] = "zzz" print(a) #outputs ['zzz', 2, 3] print(b) #outputs ['zzz', 2, 3] --> would b be a shallow copy of a because of the modification of a list element? I am having trouble distinguishing cases of shallow vs deep copy. From my current understanding: i) variable1 and a variable2 that is assigned variable1 are COPIES OF EACH OTHER ii) shallow copy: changes to one copy DO AFFECT the other copy iii) deep copy: changes to one copy do NOT affect the other copy Referring to the 3 cases above, case 1 and case 2 appears to necessitate the the deep copy concept, while case 3 the shallow copy concept. Does the specific WAY of variable modification determine the copy type? --> If so, under what condition do we assume the concept of shallow / deep copy? Or have I forgotten something important and complicating matters?