What is the output?
x = [1, 2, 3] x[1:2] = [7, 8, 9] print(x)
- [1, [7, 8, 9], 3]
- [1, 7, 3]
- [1, 7, 8, 9, 3]
- [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 ▸
x = [1, 2, 3] x[1:2] = [7, 8, 9] print(x)