Regarding List|| range | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Regarding List|| range

What is the result of this code? nums = list(range(5)) print(nums[4]) The answer is 4 in Sololearn. My perspective is the answer is 3 because list contains values as [0,1,2,3,4], then why the answer is 4

15th Dec 2018, 1:07 PM
jefrin jose
jefrin jose - avatar
1 Answer
0
it's correct. it asks for the element of index 4 from the list. the index 4 is the 5th element from the list, so: num [0] = 0 num [1] = 1 num [2] = 2 num [3] = 3 num [4] = 4
15th Dec 2018, 1:15 PM
jefrin jose
jefrin jose - avatar