ProgrammingEasyTCS NQT · Wipro pattern

What is printed?

What is printed?
x = [1, 2, 3]
x.append([4, 5])
print(len(x))
  1. A. 3
  2. B. 4
  3. C. 5
  4. D. 6

Correct answer: B. 4

append adds its argument as ONE element, so the list becomes [1, 2, 3, [4, 5]] with length 4. extend([4, 5]) would have given 5.

More Python Programming questions

Exams that ask this topic