0

Output Working

fib = {1: 1, 2: 1, 3: 2, 4: 3} print(fib.get(4, 0) + fib.get(7, 5)) How it's working?

2nd Apr 2020, 6:15 AM
Moghan kumar
Moghan kumar - avatar
2 ответов
+ 3
the get(a,b) returns fib[a] if a exists as key, else b.
2nd Apr 2020, 6:49 AM
Oma Falk
Oma Falk - avatar
+ 1
the dictionary get method has two parameters : the first is the key of the element and the second one is the default value which will be returned if the dictionary does not have such key. so fib.get(4,0)+fib.get(7,5) = 3 +5 =8 because the 7 is not a key of fib.
2nd Apr 2020, 6:50 AM
John Robotane
John Robotane - avatar