Question PRG-PY-0001
EasyWhat is the output of this code?
x = [1, 2, 3]
y = x
y.append(4)
print(len(x))
- A.
3
- B.
4
- C.
Show answer and explanation
Answer: B
y = x does not copy the list; both names refer to the same list object. Appending through y changes the list that x refers to, so its length is 4.