Python Programming - Tricky Questions - Discussion

Discussion Forum : Tricky Questions - General Questions (Q.No. 44)
44.
What is the output of the following Python code?
x = [1, 2, 3]
y = x
x += [4, 5]
print(y)
[1, 2, 3]
[1, 2, 3, 4, 5]
[1, 2, 3, 4, 5] (but with a warning)
This code will result in an error.
Answer: Option
Explanation:
The += operator modifies the list in-place, and y reflects this change.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.