Python Programming - Tricky Questions - Discussion

Discussion Forum : Tricky Questions - General Questions (Q.No. 19)
19.
What is the output of the following Python code?
a = [1, 2, 3]
b = a[:]
a[0] = 10
print(b)
[1, 2, 3]
[10, 2, 3]
This code will result in an error.
[10, 2, 3] (but with a warning)
Answer: Option
Explanation:
Slicing creates a new copy of the list, so modifying a does not affect b.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.