Why is the outpot of the last line of code single digit? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why is the outpot of the last line of code single digit?

https://code.sololearn.com/cU0DvwR3vyht

23rd May 2019, 5:52 PM
Saurabh Kundu
Saurabh Kundu - avatar
6 Answers
+ 3
Because you told it to look at the index 2 of the first array, and then the index 1 of the retrieved array, which is 2. https://code.sololearn.com/ctxaMS43CS50/#py number = 3 things = ["string", 0, [1, 2, number], 4.56] print("Index 2 of first array is: ", things[2]) print("Index 1 of array above is: ", things[2][1]) :::: Output ::::: Index 2 of first array is: [1, 2, 3] Index 1 of array above is: 2
23rd May 2019, 6:04 PM
AgentSmith
+ 2
@Tahir Iqbal I'm confused why you would show up on this thread, contribute nothing and then reference another thread you created that isn't even related to this thread?
27th May 2019, 1:48 AM
AgentSmith
+ 1
Yeah it's a single digit
23rd May 2019, 6:49 PM
thiru
+ 1
Bcuz the array "things" has an another array in it which is [1,2,3]
23rd May 2019, 6:51 PM
thiru
+ 1
[1,2,3] has a index of 2 in the things array and hence, in which, the index 1 belongs to a single number,i.e 2
23rd May 2019, 6:52 PM
thiru
23rd May 2019, 9:52 PM
Tahir Iqbal
Tahir Iqbal - avatar