Explanation:
✅ Step-by-step:
-
arr = [1, 2, 3]
→ Creates a list named arr. -
arr2 = arr
→ This does not copy the list.
→ It means arr2 refers to the same list object in memory as arr. -
arr2[0] = 100
→ Changes the first element of the list to 100.
→ Since both arr and arr2 point to the same list, this change is reflected in both. -
print(arr)
→ Outputs the modified list.
✅ Output:
Summary:
In Python, assigning one list to another variable (e.g., arr2 = arr) creates a reference, not a copy.
To make a copy, you'd need:


0 Comments:
Post a Comment