Show Python list slicing with a step, negative indices, and the fact that a slice creates a new list.
List slicing works in exactly the same way as string slicing. You write items[start:stop:step], the stop position is left out, and the step decides the direction and the spacing.
items = [0, 1, 2, 3, 4, 5]
print(items[1:4]) # [1, 2, 3]
print(items[:3]) # [0, 1, 2]
print(items[::2]) # [0, 2, 4]
print(items[::-1]) # [5, 4, 3, 2, 1, 0]
print(items[-2:]) # [4, 5]
# A slice always produces a NEW list
copy = items[:]
copy.append(99)
print(items) # [0, 1, 2, 3, 4, 5] - unchanged
print(copy is items) # False
The reversal with items[::-1] and the last two items with items[-2:] both work because a negative step starts from the end, and negative positions count back from the end.
The copy behaviour at the bottom is the part that matters most in an interview. A slice always builds a new list, so items[:] is an independent shallow copy. Changing it does not affect the original, and the two lists are different objects.
It is important to say that it is a shallow copy. If the list holds objects that can change, then those inner objects are still shared between the original and the copy. For a list of lists, items[:] gives you a new outer list that holds the very same inner lists. When you need a structure that is genuinely independent, use copy.deepcopy.
One more thing is worth knowing. You can also assign to a slice, and the lengths do not have to match. Assigning a shorter list replaces those positions and removes the extra ones, while assigning a longer one inserts the extra items. That behaviour is occasionally useful, but it is also a classic source of accidental data loss, so slice assignment deserves the same care as slice indexing.