98 views

1 Answer

1 1 vote

Inside the function, $\texttt{data}$ starts as:

[1]

The $\texttt{try}$ block prepares to return this list.

However, before the function actually returns, the $\texttt{finally}$ block must execute.

The statement $\texttt{data.append(2)}$ modifies the same list object.

So the list becomes:

[1, 2]

Since the returned object is the same list, the final output is:

[1, 2]

Correct Option: B

Answer:
Position:
Show:

Related questions

0 0 votes
1 1 answer
107
107 views
GO Classes asked Jun 5
107 views
Consider the following Python code:data = [[1, 2, 3], [4, 5], [6]] result = [x for row in data for x in row if x % len(row) == 0] print(result)What is the output of the c...
1 1 vote
1 1 answer
94
94 views
GO Classes asked Jun 5
94 views
Consider the following Python code:funcs = [] for i in range(3): funcs.append(lambda x: x + i) result = [f(10) for f in funcs] print(result)What is the output of the code...
1 1 vote
1 1 answer
92
92 views
GO Classes asked Jun 5
92 views
Consider the following Python code:values = [1, 2, 3] gen = (x * 2 for x in values) values.append(4) first = list(gen) values.append(5) second = list(gen) print(first, se...
1 1 vote
1 1 answer
98
98 views
GO Classes asked Jun 5
98 views
Consider the following Python code:grid = [[0] * 2] * 3 grid[0] = 5 grid = [7, 8] grid [0] = 9 print(grid)What is the output of the code above?[[0, 5], [9, 5], [7, 8]][...