Python List and Range Query | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Python List and Range Query

What is the result of this code? nums = list(range(5)) print(nums[4]) sol=4 Why is it 4 and not 3? can anyone please help?

18th Sep 2017, 1:21 PM
Abhishek Sarkar
Abhishek Sarkar - avatar
4 Answers
0
print(1==1.0 or 2) print(2==(2 or 1)) print((2==2)or 1) u posted this question...in tutorial of python.. u asked why 2nd case is false while others are true.. the thing is how u got 2nd case false ?? 3 cases are true..
18th Sep 2017, 1:46 PM
sayan chandra
sayan chandra - avatar
0
range(5) is eqivalent to range(0,4) list(range(5)) = list(range(0,4)) = [0,1,2,3,4] print(num[4]) >>> 4
18th Sep 2017, 1:33 PM
sayan chandra
sayan chandra - avatar
0
thanks a lot bro for the 1st one...pretty clear to me now...and for the second one you are correct...I did not realised that when I was posting...I was comparing them with numbers to see what comes up...later realised that in case of numbers all 3 were true...thanks by the way for noticing..it really helps when someone points your mistake.. :)
18th Sep 2017, 2:14 PM
Abhishek Sarkar
Abhishek Sarkar - avatar
0
glad to know it helped..
18th Sep 2017, 2:38 PM
sayan chandra
sayan chandra - avatar