Python Programming - Tricky Questions - Discussion

Discussion Forum : Tricky Questions - General Questions (Q.No. 41)
41.
What is the output of the following Python code?
a = [1, 2, 3]
b = a
a = a + [4, 5]
print(b)
[1, 2, 3]
[1, 2, 3, 4, 5]
This code will result in an error.
[1, 2, 3, 4, 5] (but with a warning)
Answer: Option
Explanation:
The concatenation creates a new list, and b still refers to the original list.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.