0

Dictionaries (literally no clue)

What is the result of this code? fib = {1: 1, 2: 1, 3: 2, 4: 3} print(fib.get(4, 0) + fib.get(7, 5))

10th Aug 2019, 6:13 AM
ScienceLuke7
ScienceLuke7 - avatar
1 Answer
+ 13
The get (x, y) (x-key, y-value) method returns the value x if it is in the dictionary, if it is not, then returns y. 4 in the dictionary is and has a value of 3, therefore returns 3. 7 in the dictionary is not therefore returns 5
10th Aug 2019, 6:25 AM
Mikhail Gorchanyuk
Mikhail Gorchanyuk - avatar