$ ./guess_the_languageProblem Solving — predict the output
Problem Solving — predict the output · medium · #32

What is printed?

a = [1, 2, 3]
b = a
b.append(4)
print(a)
  1. [1, 2, 3]
  2. [4]
  3. [1, 2, 3, 4]
  4. [1, 2, 3, [4]]
b and a reference the same list, so a sees the append.
Play Problem Solving ▸