+ 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..
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
+ 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~
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