+ 2

What is the output of this code?

I understand that the first line declares a list. I don't understand what the second line does list = [1, 1, 2, 3, 5, 8, 13] print(list[list[4]])

25th Apr 2018, 4:48 PM
Jackson Meddows
Jackson Meddows - avatar
3 Respostas
+ 9
The second one is actually a nested list indexing. It looks for the list's element which has an index number equal to the list's fifth element (or the one with the index number of 4). list[list[4]] \ / \ / \/ list[5] | | 8
25th Apr 2018, 5:09 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 2
So you have the list "list", and you want to access one of it's elements. In print(list[list[4]]) the list[4] is five. So that means print(list[list[4]]) == print(list[5]) Was this helpful?😃
25th Apr 2018, 5:55 PM
Paul Grasser
Paul Grasser - avatar
+ 1
list=[1,1,2,3,5,8,13] so, list[4]=5 list[list[4]]=list[5]=8 so is the output Instead of asking for the output run the code and get the output. If you don't understand the result then ask for the explanation, don't ask for the output.
25th Apr 2018, 5:09 PM
Koushik Naskar
Koushik Naskar - avatar