Step-by-Step Explanation:
Line 1:
x = [1, 2, 3]
A list [1, 2, 3] is created and assigned to the variable x.
Line 2:
y = x
The variable y now points to the same list object as x. Both x and y reference the same memory location.
Line 3:
x = x + [4]
This creates a new list by concatenating [1, 2, 3] (the value of x) with [4].
The new list [1, 2, 3, 4] is assigned to x.
Now x references the new list [1, 2, 3, 4], while y still references the original list [1, 2, 3].
Line 4:
print(y)
Since y still points to the original list, the output is [1, 2, 3].
Output:
[1, 2, 3]
0 Comments:
Post a Comment