Python depth copy

Source: Internet
Author: User

Tag: Print priority also port EPC depth copy style list memory

One: Shallow copy
= [123, [456= copy.copy (L1) l2[3] [03  # Modify elements of Level two list l2[11print (L1) print (L2)  

Results:

[1, 2, 3, [3, 5, 6]]
[1, 1, 3, [3, 5, 6]]

Level Two list will change with either side of the changes, L1 of the level two list if the priority change then L2 two level list will also change, similarly, L2 priority change is the same

In addition, the data of a level list is independent, it will re-open a piece of memory space and copy the data elements of the first level list, the level two list is simply a reference and will not copy

Two: Deep copy
= [123, [456= copy.deepcopy (L1) l2[3 [03  # Modify elements of Level two list l2[11print (L1) print (L2)

#结果:

[1, 2, 3, [4, 5, 6]]
[1, 1, 3, [3, 5, 6]]



Deep Copy is a re-opening of the memory space and a complete copy of the data, L1 and L2 do not affect each other

Python depth copy

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.