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

What is the output?

x = [1, 2, 3]
x[1:2] = [7, 8, 9]
print(x)
  1. [1, [7, 8, 9], 3]
  2. [1, 7, 3]
  3. [1, 7, 8, 9, 3]
  4. [1, 7, 8, 9, 2, 3]
Assigning to a slice replaces that range with the items of the new list, so the list can grow.
Play Problem Solving ▸