$ ./guess_the_languageProblem Solving — predict the output
Problem Solving — predict the output · hard · #120

What is printed?

x = [1, 2, 3]
y = x[:]
y[0] = 9
print(x[0], x is y, x == y)
  1. 1 False False
  2. 9 False False
  3. 1 True True
  4. 1 False True
A slice copies, so x is unchanged; the lists are neither the same object nor equal now.
Play Problem Solving ▸