Step-by-Step Explanation
1️⃣ Create the original list
arr = [1, 2, 3]arr points to a list in memory:
arr → [1, 2, 3]2️⃣ Make a copy of the list
arr3 = arr.copy().copy() creates a new list object with the same values.
arr3 is a separate list, not a reference to arr.
3️⃣ Modify the copied list
arr3.append(4)This only changes arr3:
4️⃣ Print original list
✅ Output
[1, 2, 3]Key Concept
| Operation | Effect |
|---|---|
| .copy() | Creates a new list |
| = | Only creates a reference |
| append() | Modifies list in place |
Compare with reference assignment:
Output:
[1, 2, 3, 4]Because both variables point to the same list.
Final Answer
๐ arr remains unchanged because arr3 is a separate copy, not a reference.
Printed Output:
[1, 2, 3]


0 Comments:
Post a Comment