Computer Science, asked by kuldeepswarnkar14, 4 days ago

Identify the output of the following Python statements.
x = [[10.0, 11.0, 12.0],[13.0, 14.0, 15.0]]
y = x[1][2]
print(y)

the answer is 15.0 but how? , explain please..

Answers

Answered by Anonymous
7

Answer:

Yes answer would be 15.0

Explanation:

As you can see in your questions there are list inside list(called nested lists), so when we assign values to y we are linking an element to it

The things happened here is that

x[1] will select second nested list because in python the counting starts from 0,1,2... and so on.

So if you want to show 1st value you have to write 0.

Now after selecting second nested list we have also write [2] after x[2], so this will select the third element of the nested list which is 15.0 and hence the answer is 15.0

If in the question it would have written just [1] whole second list would be output.

If still doubt then comment I'll help you.

Similar questions