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

28th Feb 2020, 3:41 AM
Kusum Paliwal
Kusum Paliwal - avatar
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
28th Feb 2020, 3:46 AM
LDSD
LDSD - avatar
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.
28th Feb 2020, 3:49 AM
Peter Parker
Peter Parker - avatar
0
The output was right
28th Feb 2020, 7:07 AM
Seb TheS
Seb TheS - avatar