Home > other >  Why this deep copy (copy. Deepcopy) function failure
Why this deep copy (copy. Deepcopy) function failure

Time:01-20

The import copy
A=[" a ", "B", "C", "D"]
B=[]
For a string in a:
String_1=copy. Deepcopy (string)
Print (string, "string_1 address is", id (string_1))
String_2=copy. Deepcopy (string)
Print (string, "string_2 address is", id (string_2))
Print (string, the string "address", id (string))

Print out is:
A string_1 address is 2593228521712
A string_2 address is 2593228521712
A string of address is 2593228521712
String_1 address is 2593228213104 B
String_2 address is 2593228213104 B
The address of the string is 2593228213104 B
C string_1 address is 2593228212976
C string_2 address is 2593228212976
The address of the string is 2593228212976 C
D string_1 address is 2593228395888
D string_2 address is 2593228395888
D string address is 2593228395888

String_1 string_2 and string at the same address

CodePudding user response:

If I want to make a and b two list contains the same elements (string or number), but the id is different, so what should I do?

CodePudding user response:

If I want to make a and b two list contains the same elements (string or number), but the id is different, so what should I do? Will not be able to directly make b=copy. Deepcopy (a), because each element to pass judgement to determine which added to the list, but the result could lead to the two identical, but because the same, chaos occurs on reference

CodePudding user response:

Why must be different id? Even if the same id, the string will not quote, have what relation?

CodePudding user response:

You mean list1 and list2 string is the same, but each id?
This seems to be not seen, I feel not achieve them,
Or whim I see,
  • Related