Python3-Q1 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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]])

2nd Jul 2018, 8:07 AM
Ali shayani
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/
2nd Jul 2018, 8:17 AM
Nikhil Dhama
Nikhil Dhama - avatar
+ 3
list[4] returns the fifth element of list. (4) so, list[list[4]] => list[4] => 4
2nd Jul 2018, 8:42 AM
Ulisses Cruz
Ulisses Cruz - avatar
+ 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
2nd Jul 2018, 9:02 AM
Nikhil Dhama
Nikhil Dhama - avatar
+ 1
OK. Thank you very much
2nd Jul 2018, 9:04 AM
Ali shayani
0
OK
2nd Jul 2018, 8:32 AM
Ali shayani
0
I do not understand why this code has this result? Please explain
2nd Jul 2018, 8:37 AM
Ali shayani
0
list[4] = 4 indexing starts from 0 here list [0] = 0, list [1] = 1 .. and so on. list[ list[4] ] => list[ 4 ] =>4
2nd Jul 2018, 8:43 AM
Nikhil Dhama
Nikhil Dhama - avatar
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]])
2nd Jul 2018, 8:59 AM
Ali shayani