0
How the answer is 4
What is the result of this code? nums = list(range(5)) print(nums[4]) I think The Answer should be 3 but in app the answer is 4 so my question is how the answer is 4....
3 Answers
+ 1
range(5) => numbers from inclusive 0 excluding 5
OR
[0, 1, 2, 3, 4]
Their index == their value
nums[0] == 0
nums[1] == 1
nums[2] == 2
nums[3] == 3
nums[4] == 4
0
Output of range(n) is 0,1,2,.....,n-1. So, here nums = [0,1,2,3,4]. This is why ans is 4.
0
The output was right