Skip to content
Exercises · Q2

Q.Consider the following list myList. What will be the elements of myList after each of the following operations?
myList = [10,20,30,40]

a) myList.append([50,60])
b) myList.extend([80,90])
West Bengal WbchseTextbookSubjective· 2mImportance★★★★★est
33% · 10/30 Questions
✓ Free question

append([50,60]) adds the list as one nested element → [10, 20, 30, 40, [50, 60]]; extend([80,90]) unpacks it and adds each element → [10, 20, 30, 40, 80, 90]. Same argument, completely different result.

Taking each operation on the original myList = [10, 20, 30, 40] (each part starts fresh):

a) myList.append([50,60])

myList = [10, 20, 30, 40]
myList.append([50, 60])
print(myList)
[10, 20, 30, 40, [50, 60]]

append() always adds exactly one element. Because the argument here is itself a list, that whole list becomes a single nested item at the end. Check: len(myList) is now 5, not 6, and myList[4] is [50, 60].

b) myList.extend([80,90])

myList = [10, 20, 30, 40]
myList.extend([80, 90])
print(myList)
[10, 20, 30, 40, 80, 90]

extend() walks through its argument and appends each element individually — 80 and 90 join the list as ordinary items. len(myList) is now 6, and there is no nesting.

(If instead you performed b) immediately after a) on the same list, the result would be [10, 20, 30, 40, [50, 60], 80, 90] — the nested list from append stays put and extend adds its two elements after it.)

The underlying rule — append(x) treats x as one object; extend(iterable) iterates over it. That single distinction explains both outputs, and it is why the lengths differ (5 vs 6).

✓Final answer

a) myList becomes [10, 20, 30, 40, [50, 60]] — append() inserts [50,60] as a single nested element (length 5). b) myList becomes [10, 20, 30, 40, 80, 90] — extend() adds 80 and 90 as separate elements (length 6).

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.