+ 5

list=[1,1,2,3,5,8,13] What will be output if next line of code is print (list[list[4]])??? and how???

25th Oct 2016, 4:34 AM
Manish27
Manish27 - avatar
13 RĂ©ponses
+ 51
It's easy but but tricky .... first of all it will access the element at Index 4 of the list. Inner list will be solved first print (list [list [4]]) As you know list start with Index 0 so in the list 4th index value is 5 print(list [5]) now this will print element of index 5 which is 8 Answer is 8
25th Oct 2016, 5:19 AM
Waqas Asghar Bhalli
Waqas Asghar Bhalli - avatar
+ 18
1. Look at what is the value of list[4]. We see it is 5. 2. Supstitude list[4] with its value. (5) 3. Now we have list[5] which is 8 :)
25th Oct 2016, 4:46 PM
Remmae
Remmae - avatar
+ 8
Or you can test it in py console)) Like this: >>> list=[1,1,2,3,5,8,13] >>> list [1, 1, 2, 3, 5, 8, 13] >>> list[4] 5 >>> list[5] 8 >>> list[list[4]] 8
25th Oct 2016, 6:42 AM
Artur Makarov
Artur Makarov - avatar
+ 3
I'm mathematical terms, it is f°f (f composed of f). All of the other comments explain the concept.
25th Oct 2016, 8:00 PM
Parker McMullin
Parker McMullin - avatar
+ 1
Algorithm: Word used by programmers when they dont`t want to explain what they did. https://www.python.org/doc/humor/
7th Aug 2017, 5:56 PM
Nico 'S
Nico 'S - avatar
+ 1
8
26th Oct 2018, 8:03 AM
Houcem Eddine Aouissaoui
Houcem Eddine Aouissaoui - avatar
+ 1
Hi can someone break down what the code is commanding? I get the idea that the 4th element of the list is 5. So the next part is where is struggle: how does it then move to become 8 I think i need to understand this part of the code (what the brackets are doing here?) (list[list[4]]) I think i got it somewhat... so we are telling the code to look at the list 4th value which is 5. To then take this 5 and reuse it as the 5th index in the list to print .. seems awfully complicated.
7th Oct 2020, 4:17 PM
Bart Craenmehr
0
well explained everyone👍
29th Oct 2016, 6:42 AM
Manish27
Manish27 - avatar
- 1
ans : 8
10th Feb 2021, 11:53 AM
Md Momin Uddin Hridoy
Md Momin Uddin Hridoy - avatar
- 1
Answer is 8
12th May 2021, 6:06 AM
Sangeetha Geetha
Sangeetha Geetha - avatar
- 1
8
18th May 2021, 1:31 PM
Limitha M
Limitha M - avatar
- 1
What's the output of this code? list = [1, 1, 2, 3, 5, 8, 13] print(list[list[4]]) Answer is 8
20th May 2021, 10:20 AM
Janhvi Tiwari
Janhvi Tiwari - avatar
- 4
The answer is 8 bruh
3rd Feb 2020, 12:15 PM
Femzi
Femzi - avatar