0

List function. Why is the answer 8?

list = [1, 1, 2, 3, 5, 8, 13] print(list[list[4]]) Question from one of the tutorials of python If you were to only use the list function once it would give the answer as 5. I don't understand why when you use the list function twice as in this instance the answer is 8. Can someone please explain it to me. Also why would you use the list function twice in the first place. what is the process that is happening here?

7th Mar 2020, 2:36 PM
Kishan Vekaria
1 Odpowiedź
+ 1
You unpack it from the right so: list[list[4]] > list[5] > 8
7th Mar 2020, 2:39 PM
Amir Galanty
Amir Galanty - avatar