copy.copy()
and copy.deepcopy()
just copy the reference for an immutable object like a tuple.
How can I create a duplicate copy of the first immutable object at a different memory location?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
try this:
And I think adding an empty tuple is much better.
You're looking for
deepcopy
.Admittedly, the ID of these two tuples will point to the same address. Because a tuple is immutable, there's really no rationale to create another copy of it that's the exact same. However, note that tuples can contain mutable elements to them, and deepcopy/id behaves as you anticipate it would:
Add the empty tuple to it:
Concatenating tuples always returns a new distinct tuple, even when the result turns out to be equal.