- 1
What is the result of this code? nums = [9, 8, 7, 6, 5] nums.append(4) nums.insert(2, 11) print(len(nums))
I need help
5 Answers
+ 5
length will be 7.
nums = [9, 8, 7, 6, 5]
nums.append(4) #[9,8,7,6,5,4]
nums.insert(2, 11) #[9,8,11,7,6,5,4]
print(len(nums))
+ 2
7
+ 1
7 is the Ans.
nums.append(4) addes a 4 to the end
So [9,8,7,6,5,4]
whereas nums.insert(2, 11) adds 11 at the second place of the list
so [9,8,11,7,6,5,4]
so totally 7 is the length
+ 1
What is the output of this code?
nums = [2,4,8,9,5]
nums.insert(1, 3)
nums.remove(9)
nums.insert(0, nums.count(8))
print(nums[3])
0
4