Reference replication, shard Copy, full replication in Python
First look directly at the example:
>>>l1=[1,2,3]>>>L11 = L1>>>l2=[4,5, L1]>>>l2[4,5, [1,2,3]]>>>L3 = l2[:]>>>l3[4,5, [1,2,3]]>>>ImportCopy>>>L4 = copy.deepcopy (L2)>>>l4[4,5, [1,2,3]]>>>l2[1] =6>>>l2[4,6, [1,2,3]]>>>l3[4,5, [1,2,3]]>>>l4[4,5, [1,2,3]]>>>l1[0] =7>>>l1[7,2,3]>>>l11[7,2,3]>>>l2[4,6, [7,2,3]]>>>l3[4,5, [7,2,3]]>>>l4[4,5, [1,2,3]]
Description
- Copying using the Shared object application will only add a new reference to the existing object and will not generate new objects in memory (see L11 vs. L1).
- Using a Shard method to copy a sequence type such as a list, only the contents of the current sequence are copied, and the data structures within the sequence are not copied (see L1, L2, L3 contrast).
- Dictionaries can also be copied with copy methods, but with 2 limitations.
- The Copy standard Template Library is able to generate a complete copy, eliminating the problem of not copying the data structures in the sequence in the previous article (see Comparison of L3 and L4 values).
- 2 and 3 are called top-level replication and cannot replicate nested data structures.
Reference replication, shard Copy, full replication in Python