Lists & Tuples · Question 15 · Medium

A two-element slice of a list is replaced by a one-element list. What is printed?

a = [0, 1, 2, 3, 4]
a[1:3] = [9]
print(a)
  1. [0, 9, 9, 3, 4]
  2. [0, 9, 2, 3, 4]
  3. [0, 9, 3, 4]
  4. [0, [9], 3, 4]
Answer and explanation

Answer: C. [0, 9, 3, 4]

Explanation: Slice assignment replaces the whole slice with the items of the new list, and the sizes need not match. Indexes 1 and 2 (values 1 and 2) are removed and a single 9 takes their place.

Previous: Kavya has a list a and wants b to be a separate list with the same items, so… · Next: The list a is extended once with + and once with += through a second name…

Practise lists & tuples

Try a fresh set of lists & tuples questions with an explanation after every answer, free and without signing up: Lists & Tuples practice. Or sit a full placement mock test.

More lists & tuples questions

More python practice

Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge