+ 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

31st Aug 2019, 4:00 PM
Vanita Bora
Vanita Bora - avatar
5 Respostas
+ 4
(list[list[4]]) first inner list[4] will return 5 And the expression becomes list[5] which in return evaluates to 8
31st Aug 2019, 4:20 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 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.
31st Aug 2019, 7:27 PM
Seb TheS
Seb TheS - avatar
+ 1
because print(list[list[4]]) return 5 of (list[--->list[4]<---]) and 5 becomes the value of list print(--->list[5]<---)
31st Aug 2019, 7:05 PM
Jean C. Estevez T.
Jean C. Estevez T. - avatar
+ 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 :)
1st Sep 2019, 9:29 AM
Mai Dan Nguyen
Mai Dan Nguyen - avatar
+ 1
How can you create a multiplication table using list comprehension?
22nd Oct 2020, 5:53 AM
Arwa David
Arwa David - avatar