Question 2 of 16intermediate🔧 ApplyShort Answer2 marks

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

(i)

myList.append([50,60])

Answer

The append() function adds its argument as a single element to the end of the list. When myList.append([50, 60]) is executed on the list [10, 20, 30, 40], the list [50, 60] is added as a single nested element. The resulting elements of myList are: [10, 20, 30, 40, [50, 60]].

(ii)

myList.extend([80,90])

Answer

The extend() function adds each element of the iterable argument individually to the list. When myList.extend([80, 90]) is executed on the original list, the values 80 and 90 are appended separately. The resulting elements of myList are: [10, 20, 30, 40, 80, 90].

Explanation

The question requires differentiating between append() and extend() as referenced in the context's Exercise Question 5. append() treats the input as a single object (creating a nested list), whereas extend() iterates through the input and adds individual elements.