Python 3 Tutorial, Modul 2 Quiz | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Python 3 Tutorial, Modul 2 Quiz

Hi guys. I need your help. This is a task: "What is the output of this code? list = [1, 1, 2, 3, 5, 8, 13] print(list[list[4]])" I wrote it in text redactor and started... Well, the answer is 8. But I really dunno how this process work. Can anybody explain i details?

21st Dec 2017, 9:40 AM
Adam Kandur
Adam Kandur - avatar
3 Answers
+ 6
print(list[list[4]]) list[4]=5 list[list[4]]=list[5] print(list[list[4]])=print(list[5])=8 so finally the output is 8 it is executed from most inner to outer list so first list[4] value is find which is 5 then list[5] value is find which is 8 then it will print the value 8
21st Dec 2017, 9:51 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 1
ok, now i got it
21st Dec 2017, 11:28 AM
Adam Kandur
Adam Kandur - avatar
0
I think @GAWEN STEASY is right. You just have to start at the INNER list[4] =5 then the OUTER list[5] =8
21st Dec 2017, 11:26 AM
monotom
monotom - avatar