 What do the extra brackets do? | Sololearn: Learn to code for FREE!

+5

# What do the extra brackets do?

What is the output of this code? list = [1, 1, 2, 3, 5, 8, 13] print(list[list]) Why does it print 8?

+10

list = 5 list[list] = list = 8

+6

Solve it from the inside out. list is the element at index position 4, which is 5. So list[list] is the same as list list is the element at index position 5, which is 8. 😊

+5

list accesses the fifth element of list, which is 5. list[list] hence accesses list, which is the sixth element of list, 8.

+5

Three answers for the price of one 😄

+4

list = [1, 1, 2, 3, 5, 8, 13] print(list[list]) 1. list's index start from 0 then 1 then 2... 2. ' list ' will calculated first list = 5 3. then list[ list ] = list and, list = 8 thats why it prints 8

+2

Good question,,,, list means the first value of the array. So, list is the 5th value of the array means 5; So, list[list]->list means the 6th value of the array means 8; So, the answer is 8;

+1

list is the element at index position 3, the quarter position, because in programming you start with the 0. The first element would be list and list would be the second element. exmple: list = [h, e, l, l, o] print(list[list]) output: the O of the list

0

I hate questions like this... like a trick question or something? is there a real world example where you might use this other than to just try to confuse someone looking at the code? 😳

0

Thank you everyone!!! I get it now!

-1