+ 3
Lists
list = [1, 1, 2, 3, 5, 8, 13] print(list[list[4]]) how does this equal to 8??? I don't understand this pls can I get an answer
5 Respuestas
+ 4
(list[list[4]])
first inner list[4] will return 5
And the expression becomes list[5] which in return evaluates to 8
+ 4
List indexing appears 2 times in the program.
When you index an item from a list, it returns the corresponding list item for other operations to use.
In:
list[list[4]]
list[4] is 5, because 5 is the 5th item in the list.
list[4] returned 5 for another indexing to be used:
list[list[4]] -> list[5]
And finally we got 8.
list[5] is 8 because 8 is the 6th item in the list.
+ 1
because print(list[list[4]]) return 5 of (list[--->list[4]<---]) and 5 becomes the value of list print(--->list[5]<---)
+ 1
list[4] returns 5, which is the 5th item in the list. Then the outtermost ‘list’ will take this returned value ‘5’, so it becomes list[5], which returns the 6th value in the list, which is 8. Remember that when counting, it always counts from 0, so the 1st item is counted as 0, then 2nd as 1, 3rd as 2 ...
I hope this help :)
+ 1
How can you create a multiplication table using list comprehension?