153 views
3 3 votes

Consider the following Python code:

info = ["GO", [10, 20, [30, 40]], "DA"]

info[1][2][0] = info[1][2][0] + 5

print(info[1][2], info[1][1])

What is the output of the code above?

  1. [30, 40] 20
  2. [35, 40] 20
  3. [35, 45] 10
  4. [30, 45] 20

1 Answer

1 1 vote

The list contains another list inside it.

info = ["GO", [10, 20, [30, 40]], "DA"]

The expression $\texttt{info[1]}$ gives the inner list:

[10, 20, [30, 40]]

The expression $\texttt{info[1][2]}$ gives the nested list:

[30, 40]

The expression $\texttt{info[1][2][0]}$ gives $\texttt{30}$.

info[1][2][0] = 30 + 5 = 35

So $\texttt{info[1][2]}$ becomes $\texttt{[35, 40]}$.

Also, $\texttt{info[1][1]}$ is $\texttt{20}$.

Therefore, the output is:

[35, 40] 20

Correct Option: B

Answer:
Position:
Show:

Related questions

2 2 votes
1 1 answer
127
127 views
GO Classes asked Jun 15
127 views
Consider the following Python code:data = ["GATE", 2026, 3.5, True] data = data + int(data[3]) data[0] = data[0] + str(data ) print(data)What is the output of the code ...
1 1 vote
2 2 answers
192
192 views
GO Classes asked Jun 15
192 views
Consider the following Python code:a = [1, 2, 3] b = a b[0] = 9 a = a[0] + b print(a, b)What is the output of the code above?[1, 2, 3] [9, 2, 3][9, 2, 3] [1, 2, 11][9, ...
2 2 votes
1 1 answer
125
125 views
GO Classes asked Jun 15
125 views
Consider the following Python code:letters = ["g", "a", "t", "e", "d", "a"] x = letters[-1] + letters[-3] y = letters[-len(letters)] print(x, y)What is the output of the ...
3 3 votes
1 1 answer
150
150 views
GO Classes asked Jun 15
150 views
Consider the following Python code:nums = [4, 8, 15, 16, 23] result = nums[0] + nums[3] print(result, nums )What is the output of the code above?19 1520 1520 1624 15