1L1 = [1, 2, 3]2L2 =L13L1.append ('a')4 Print(L1, L2)#Deep Cpoy5 6L1 = [1, 2, 3]7L2 = L1.copy ()#Shallow Copy8L2.append ('a')9 Print(L1, L2)
View Code
1. Other Codes
1 #Assignment Operations2 #L1 = [A]3 #L2 = L14 #l1.append (' a ')5 #print (L1,L2)6 7 #Copy8 #L1 = [A]9 #L2 = l1.copy ()Ten #print (L1,L2) One #Print (ID (L1), id (L2)) A #l2.append (' a ') - #print (L1,L2) - the #L1 = [1,2,[4,5,6],3] - #L2 = l1.copy () - - #Print (L1,id (L1)) + #Print (L2,id (L2)) - #l1.append (' a ') + #print (L1,L2) A #l1[2].append (' a ') at #print (L1,L2) - #Print (ID (l1[2))) - #Print (ID (l2[2))) - ImportCopy - #L1 = [1,2,[4,5,6],3] - #L2 = copy.deepcopy (L1) in #Print (L1,id (L1)) - #Print (L2,id (L2)) to #l1[2].append (' a ') + #print (L1,L2) - the #L1 = [1,[1],2,3,4] * #L2 = l1[:] $ #l1[1].append (' a ')Panax Notoginseng #what is the result of L2? - the + #Print (L1,id (L1)) A #Print (L2,id (L2)) the #print (l1[1] is l2[1]) + - #li = [' Alex ', ' Taibai ', ' Wusir ', ' Egon '] $ #For I in Li: $ #Print (Li.index (i), i) - - #For Index,i in Enumerate (li,1): the #print (index,i)
View Code
Python depth copy