New course! Every coder should learn Generative AI!
Try a free lesson0
Python3-Q1
What is the output of this code? list = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] print(list[list[4]])
8 Answers
+ 5
Output: 4
use playground before posting such questions, you can easily get the output of this. if you want explaination, then ask accordingly.
Once go through this thread also
https://www.sololearn.com/discuss/1316935/?ref=app
Edit:
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2431/
+ 3
list[4] returns the fifth element of list. (4)
so,
list[list[4]] => list[4] => 4
+ 1
list = [1,1,2,3,5,8,13]
list[4] = 5 (value at index 4==> fifth element)
list[5] = 8 (value at index 5==> sixth element)
list[ list[4]] ==> list [5] ==> 8
+ 1
OK. Thank you very much
0
OK
0
I do not understand why this code has this result?
Please explain
0
list[4] = 4
indexing starts from 0
here list [0] = 0, list [1] = 1 .. and so on.
list[ list[4] ] => list[ 4 ] =>4
0
Thankful. But I code this on the (playground) and its output was 8, but the correct output was 5
list = [1, 1, 2, 3, 5, 8, 13]
print(list[list[4]])