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