+ 1

What's the usage of print(list[list[int]])

While going through the question for Python, I have seen a question with the following code: CODE: list = [1, 2, 3, 4, 5, 6] print(list[list[1]]) OUTPUT : 3 I have tried it, and tried to understand it but I don't get it. Can someone explain please ?

23rd Dec 2019, 2:08 PM
Adil D.
Adil D. - avatar
2 ответов
+ 2
You have start with the inner most [ ] : list[1] - > the item on index 1 is the value 2 So list[1] = 2 The next one is then list[2] - > gives the value on index 2, which is the value 3 That's all.
23rd Dec 2019, 2:32 PM
Coding Cat
Coding Cat - avatar
+ 2
Check the list from inside first, list[1]. list[1] is 2. So list[list[1]] is list[2]. list[2] is 3. list[list[1]] == list[2] == 3
23rd Dec 2019, 2:35 PM
你知道規則,我也是
你知道規則,我也是 - avatar