+ 2

I didn't see this covered in the lesson and I can't move forward til I understand

What is the output of this code? list = [1, 1, 2, 3, 5, 8, 13] print(list[list[4]]) Please explain to me what this is asking, how the answer is 8, and please give an alternative example. I do not want to go forward until I understand.

5th Jan 2020, 5:21 PM
Claron Chatmon
Claron Chatmon - avatar
5 odpowiedzi
+ 7
The inner part list [4] = 5 then list [5]=8 You should first find the value of the most inner part
5th Jan 2020, 5:25 PM
Pattern
Pattern - avatar
+ 5
list[list[4]]= list[5]=8 The value at 4th index is 5 and the value at 5th index is 8 list[list[0]]=list[1]=1 can you understand?
5th Jan 2020, 5:26 PM
Geek
Geek - avatar
+ 2
it always follows order of operations :)
5th Jan 2020, 9:28 PM
꧁༺ Jenspi ༻꧂
꧁༺ Jenspi ༻꧂ - avatar
+ 1
It's like var=list [4] a=5 list [a] Print (List[5]) 8
5th Jan 2020, 5:32 PM
Pattern
Pattern - avatar
+ 1
OMG. I didn't comprehend that at all. It's like an order of operations. Get the inner index first then get the index of the outer. THANKS SO MUCH!
5th Jan 2020, 7:48 PM
Claron Chatmon
Claron Chatmon - avatar