Python depth copy

Source: Internet
Author: User
Tags shallow copy

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.