Python Programming - Tricky Questions - Discussion

Discussion Forum : Tricky Questions - General Questions (Q.No. 5)
5.
What will be the output of the following Python code?
x = [1, 2, 3]
y = x
y[0] = 10
print(x)
[10, 2, 3]
[1, 2, 3]
[10, 2, 3] (but with a warning)
[1, 2, 3] (but with a warning)
Answer: Option
Explanation:
Both x and y reference the same list object. Therefore, modifying y also modifies x, resulting in the output [10, 2, 3].
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.