Casting things as list | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Casting things as list

list = [1, 1, 2, 3, 5, 8, 13] print(list[list[4]]) I thought the answer was 5 but running the code gives me 8. I understand that print(list[4]) gives 5, but why is it calling the variable name "list" and then calling list[4]

31st Aug 2020, 8:49 PM
Michael King
Michael King - avatar
2 Answers
+ 2
Nevermind, I saw another post where they explained it. Solve for the item in parentheses which is list[4] which would be 5. So then list[5] would be 8.
31st Aug 2020, 8:51 PM
Michael King
Michael King - avatar
+ 2
If you got your answer then what is the use of this question before asking questions just a research over it to field its solution if possible
1st Sep 2020, 1:39 AM
Ayush Kumar
Ayush Kumar - avatar