0
I'm not comprehending this code, help please?
number = 3 things = ["string", 0, [1, 2, number], 4.56] print(things[1]) print(things[2]) print(things[2][2]) that last line is supposed to be 3 but im not getting how that works out.
4 Respostas
+ 14
The output I get when I run your code is:
0
[1,2,3]
3
So the last line is 3. Is that not what you were expecting?
+ 14
Remember the second list is nested so Python counts it like this:
0 ="string"
1= 0
2 = the nested list
Then:
0 = 1
1 = 2
2 = number
+ 1
yes I just forgot about the nested part of it, this is my first language :) thanks!
- 1
print(things[2]) is [1,2,number] and the index 2 of that list is number.