Skip to content

Question 13

Evaluate:

{2: 4, 3: 9, 5: 25}.get(4, 0)
Hint

The .get() method takes in 1 or 2 parameters:

  1. (compulsory) Value contained in the dictionary by the given value as the hashed key
  2. (optional) Returned value should the value at key (first value) does not exist
Solution

{2: 4, 3: 9, 5: 25} does not have a key 4, hence there is no value to be retrieved. However, since we defined a value to be returned in this kind of scenario here, it returns 0.

Answer
0