192 views
0 0 votes

What is the final value printed by the following Python code snippet?
 

def mutate_dict(d):
    d['a'] = 20
    d['c'] = 40
    
d1 = {'a': 10, 'b': 20}
d2 = d1
d2['b'] = 30
mutate_dict(d1)
print(d2['a'] + d1['b'])
  1. $60$
     
  2. $50$
     
  3. $40$
     
  4. Cannot be determined

1 Answer

0 0 votes

This question tests the understanding of mutable objects (dictionaries) and variable referencing in Python. Dictionaries are mutable, and assignments like $\verb|d2 = d1|$ create a shared reference.

$\verb|d2['a']|$ is $20.$

$\verb|d1['b']|$ is $30.$

Result: $20+30=50$.

Answer:
Position:
Show:

Related questions

2 2 votes
2 2 answers
355
355 views
GO Classes asked Dec 19, 2025
355 views
A Perfectly balanced binary search tree (BST) contains $15$ distinct integers.The largest element is stored at the rightmost node of the tree.Which of the following eleme...
2 2 votes
1 1 answer
207
207 views
GO Classes asked Dec 19, 2025
207 views
Consider An array of $n$ Comparable objects that is sorted except for $k$ randomly located pairs of adjacent elements that have been swapped (each element is part of at m...
0 0 votes
1 1 answer
202
202 views
GO Classes asked Dec 19, 2025
202 views
What is the time complexity of the function log_plus_linear (n) in terms of the input size $n$ (where $n$ is a positive integer)?def log_plus_linear(n): count = 0 ...
2 2 votes
1 1 answer
215
215 views
GO Classes asked Dec 19, 2025
215 views
What is the output of the following Python code snippet?L1 = [1, 2, [3, 4]] L2 = list(L1) L3 = L1 L1[0] = 99 L2 [0] = 88 L3.append(5) print(L1 [0] + len(L2))$88$ $91$ $92...