Python hep needed- understanding list indexing | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Python hep needed- understanding list indexing

help me understand why the answer to the following code is 8: list=[1,1,2,3,5,8,13] print(list[list[4]]) I have a basic understanding of indexing however I don't understand this code. Please help.

25th Nov 2017, 5:17 AM
Gael Gatera
Gael Gatera - avatar
3 Answers
+ 2
Indexing starts from 0. print(list[list[4]]) will print the value in the list at index list[4] list[4] = 5th element = 5. list[list[4]] = list[5] = 6th element = 8.
25th Nov 2017, 5:46 AM
Meharban Singh
Meharban Singh - avatar
+ 1
oh wow that made complete sense. Again completely new to this. thanks
25th Nov 2017, 5:55 AM
Gael Gatera
Gael Gatera - avatar
+ 1
Anytime :-)
25th Nov 2017, 5:59 AM
Meharban Singh
Meharban Singh - avatar