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?
4 odpowiedzi
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..
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
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.. :)
0
glad to know it helped..