Module 2 Quiz | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Module 2 Quiz

Why is the answer to the following code 8 and not 5? list = [1, 1, 2, 3, 5, 8, 13] print(list[list[4]])

15th Jun 2020, 2:56 AM
Steve Chinappi
Steve Chinappi - avatar
1 Answer
+ 6
Look, do you know what does list[number] do? It returns the list item indexing 'number'! So, list[4] means the 5th item of the list or which index is 4. And it is 5 Now you get, print(list[list[4]]) → print(list[5]) list[5] refers to the 6th item of the list which is 8! So you get 8 as the output.
15th Jun 2020, 3:06 AM
M Tamim
M Tamim - avatar