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]) ii. myList.extend([80, 90])
Question
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])
ii. myList.extend([80, 90])
✨ Free AI Tools for You
Powered by Chatterbot AI
Answer
After performing the provided operations on myList
, the changes will be as follows:
myList.append([50,60])
The
append
method will add[50, 60]
as a single element (nested list) at the end ofmyList
.Result:
myList = [10, 20, 30, 40, [50, 60]]
myList.extend([80, 90])
The
extend
method will add each element of[80, 90]
individually to the end ofmyList
.Result:
myList = [10, 20, 30, 40, [50, 60], 80, 90]
So, the final elements of myList
after both operations will be:
[10, 20, 30, 40, [50, 60], 80, 90]
India's 1st AI Doubt Solver for CBSE, JEE, and NEET
Ask a Question for Freeand then it's just ₹212 a month