+ 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]])
3 Réponses
+ 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
+ 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?😃
+ 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.