What is the result of this??????? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the result of this???????

nums=list(range (5)) Print (mums[4]) /*. The answer is 4 why ???? */

13th Jul 2020, 8:06 PM
Uddeshya Maurya
Uddeshya Maurya - avatar
2 Answers
+ 4
Nums = [0,1,2,3,4] Nums[0] = 0 Nums[1] = 1 Nums[2] = 2 Nums[3] = 3 Nums[4] = 4 Never forget: indexing starts at 0 unless stated otherwise. Hope this helps 😃😃
13th Jul 2020, 8:13 PM
Tomiwa Joseph
Tomiwa Joseph - avatar
+ 2
range is a generator function and looks something like this: def range(n): i = 0 while(i<n): yield i # yield keyword gives new number every time i += 1 take look at my code for your reference https://code.sololearn.com/c799w4wspvRZ
13th Jul 2020, 8:34 PM
Milind Yadav
Milind Yadav - avatar