+ 1

Code

What is the result of this code? nums = [9, 8, 7, 6, 5] nums.append(4) nums.insert(2, 11) print(len(nums)) How 7?

21st Feb 2018, 1:44 PM
Jordan
Jordan  - avatar
2 Answers
+ 3
because len() counts how many items are in the list. at first there are 5, you append 4 which goes to end of the list so len is 6 then you insert 11 to position 2 and so the len becomes 7
21st Feb 2018, 2:01 PM
Markus Kaleton
Markus Kaleton - avatar