i need help with list list=[1,2,3,4,5,6] print(list[list[4]]) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

i need help with list list=[1,2,3,4,5,6] print(list[list[4]])

what is going on here why does it print the last element?

22nd Oct 2016, 1:32 PM
toygrill11
7 Answers
+ 6
Indexes start at 0, so list[4] is the 5th element of the list, which is 5, and list[list[4]] is list[5], ie the 6th element of the list, 6.
22nd Oct 2016, 1:52 PM
Zen
Zen - avatar
+ 2
got it thank you
22nd Oct 2016, 2:08 PM
toygrill11
+ 1
wait so the first list of the list[list[4]] simply indexes one farther? so is it a complicated way of writing list[5] or does the nested list go first pulls the number from the list for the in nested list?
22nd Oct 2016, 2:05 PM
toygrill11
+ 1
list[list[4]] is only list[5] here because the 5th element of this particular array is 5.
22nd Oct 2016, 2:10 PM
Zen
Zen - avatar
0
because the last element of the list matches list[5]
22nd Oct 2016, 3:35 PM
Yves Guillaume A. Messy
Yves Guillaume A. Messy - avatar
0
num=7 if num>3: print("3") if num<5: print("5") if num==7 print ("7") explain me briefly
21st Nov 2016, 2:41 PM
Sree Latha
Sree Latha - avatar
0
spam=7 if spam>5: print("5") if spam>8 print ("eight") Both statements are true but why it gives only first answer
21st Nov 2016, 2:43 PM
Sree Latha
Sree Latha - avatar