+ 3

What's the result of this code? Nums=[9;8;7;6;5] nums.append(4) nums.insert(2;11) print(len(nums))

I was sure that it's 8 but when I saw the answer is 7 I've confused a lot....Pls. can u clarify this..

11th Jul 2020, 6:15 PM
Siddiraju Manaswi
Siddiraju Manaswi - avatar
4 Answers
+ 5
the .insert() function takes two parameters. - an index - what to insert nums.insert(2,11) inserts 11 at the 2 index you get it
11th Jul 2020, 6:18 PM
Slick
Slick - avatar
+ 3
[9,8,7,6,5] [9,8,7,6,5,4] [9,8,11,7,6,5,4] , so the length of the array is 7. hope this help~
11th Jul 2020, 6:23 PM
Esch
Esch - avatar
0
Hey its easy ... First append : it adds 4 to the end in Nums Now insert operation : where 11 is inserted at position 2 aka the spot where 7 was earlier . Now when u find the length it is 5 + (appended 4) +(inseted 11) = 7
11th Jul 2020, 6:24 PM
Naren Matesh
Naren Matesh - avatar