ProgrammingEasyAccenture · Capgemini pattern

What is printed?

What is printed?
a = [1, 2, 3]
a += [4]
a = a + [5]
a.extend("67")
print(a)
  1. A. [1, 2, 3, 4, 5, 67]
  2. B. [1, 2, 3, 4, 5, '67']
  3. C. [1, 2, 3, 4, 5, '6', '7']
  4. D. [1, 2, 3, 4, 5, 6, 7]

Correct answer: C. [1, 2, 3, 4, 5, '6', '7']

+= and + with a list add its elements. extend iterates its argument, and iterating the string "67" yields the characters '6' and '7'. append("67") would add one element '67'.

More Python Programming questions

Exams that ask this topic