Lists & Tuples · Question 11 · Medium

A starred name is used while unpacking a list. What is printed?

first, *rest = [1, 2, 3, 4]
print(first, rest)
  1. 1 [2, 3, 4]
  2. 1 2
  3. 1 (2, 3, 4)
  4. ValueError
Answer and explanation

Answer: A. 1 [2, 3, 4]

Explanation: first takes the first element and the starred name collects everything left over. The collected values are always stored in a list, so rest is [2, 3, 4].

Previous: remove() and pop() are used on a queue of token numbers. What does this print? · Next: For the tuple t = (1, 2, 3), which of these operations is NOT allowed?

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