+ 2

how the last one will become 3???

number = 3 things = ["string", 0, [1, 2, number], 4.56] print(things[1]) print(things[2]) print(things[2][2]) ans:-> the output is 0 [1,2, number] 3 my question is how the last one will become 3???

31st Aug 2019, 8:19 AM
Suraj Das
Suraj Das - avatar
4 ответов
+ 4
I would like to try to explain in a bit more depth. number is a variable with an assigned value = 3 things = a list with 4 items The index of the items are: 0: 'string' 1: 0 2: [1, 2, number] =>(another list) 3: 4.56 The index of the inner list is: 0: 1 1: 2 2: number =>( value = 3) Print(things[2][2]) is an index slice of things which calls the inner list, which is then index sliced again which results in number. number = 3
31st Aug 2019, 9:34 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 6
It's a 2D array. The first [2] makes [1,2,number], the second [2] goes inside, referring to number, which is 3.
31st Aug 2019, 8:26 AM
Lieke Franssen
Lieke Franssen - avatar
+ 4
Thank you also
3rd Sep 2019, 9:09 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Thanks alot 😍😍😍😍
3rd Sep 2019, 9:08 AM
Suraj Das
Suraj Das - avatar