Lists & Tuples · Question 2 · Easy

One value is appended and another inserted at the front of a list. What is printed?

nums = [3, 1, 2]
nums.append(5)
nums.insert(0, 9)
print(nums)
  1. [3, 1, 2, 5, 9]
  2. [9, 3, 1, 2]
  3. [0, 3, 1, 2, 5]
  4. [9, 3, 1, 2, 5]
Answer and explanation

Answer: D. [9, 3, 1, 2, 5]

Explanation: append(5) adds 5 at the end, giving [3, 1, 2, 5]. insert(0, 9) places 9 at index 0 and shifts everything else right.

Previous: What does this slice of the list marks print? · Next: Which expression creates a tuple containing the single element 7?

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