+ 2
Python List Class
What is the output of this code? list = [1, 1, 2, 3, 5, 8, 13] print(list[list[4]]) This makes no sense to me. The answer was 8. Can anyone explain?
4 odpowiedzi
+ 5
list[list[4]]
list[5]
8
# note that index starts at 0
+ 2
I did not understand that I needed to compute (list[list[4]]) to (list[5]). That was the missing link. Thank you, Pedro! 👍🏻
+ 2
list[4] is fifth element in list (cause indixes start from 0), so
[0] is 1
[1] is 1
[2] is 2
[3] is 3
[4] is 5
[5]is 8
[6] is 13.
So, list[4] is 5.
Now we get
print(list[5]) and solve it same way - look for 6th element in list. It is 8.
So, output is 8.
+ 1
Thank you for a more verbose explanation. I think I have it now. You guys (and gals) are amazing! 👍🏻👍🏻