Python Programming - Tricky Questions - Discussion

Discussion Forum : Tricky Questions - General Questions (Q.No. 34)
34.
What is the output of the following Python code?
x = [1, 2, 3]
y = x
y[0] = 10
print(x)
[1, 2, 3]
[10, 2, 3]
[10, 2, 3] (but with a warning)
[1, 2, 3, 10]
Answer: Option
Explanation:
y is assigned a reference to the same list as x, so modifying y also modifies x.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.