What is the output of the following Python code snippet?
a = [1, 2, 3]
b = a
b[0] = 99
print(a, b)
b = a
b[0] = 99
print(a, b)
Correct answer
B. [99, 2, 3] [99, 2, 3]
B. [99, 2, 3] [99, 2, 3]
b = a copies the reference, not the list, so changing b changes a as well.
Asked in: Python Interview Lists
https://docs.python.org/3/tutorial/datastructures.htmlNot sure why the answer is B? Ask here and get an explanation.