Lists & Tuples · Question 5 · Easy

A list is appended to another list. What length does this print?

x = [1, 2]
x.append([3, 4])
print(len(x))
  1. 4
  2. 2
  3. 3
  4. TypeError
Answer and explanation

Answer: C. 3

Explanation: append() adds its argument as one single element, so x becomes [1, 2, [3, 4]] with length 3. To add 3 and 4 as separate elements, extend() is used instead.

Previous: Three facts about a tuple of scores are printed. What is the output? · Next: An element of a tuple is assigned a new value. What happens?

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