0
print([2][2]) please help me understand this....
4 Answers
+ 1
First,there is no list name. But, assuming there is one, the interpreter first looks for the item in the list at the first index typed, so for example list[2] is also a list. And then, you can specify an index with 2 others square brackets.
Does it answer your question?
0
This statement gives an index error.
The first [2] inside the print is a valid definition of a list that has a single element.
The second [2] is trying to make a slice operation of this list and tries to retrieve the element with index 2. This is not possible because it has only 1 element whose index is 0. Hence the error.
0
Tibor Santa
Oooh ok I didn't understand the statement like this...
0
SpaceNerd is right, for example:
lis[2] | 0 | 1 | * 2 * |
lis[2][2] |0, 1, *2*|
lis = [[1,2,3],[4,5,6], [7, 8, 9]]
print(lis[2][2]) = 9