0

Please explain the calculations

fib={1:1,2:1,3:2,4:3} print(fib.get(7,5)) Answer came : 5 . What's the background calculation?

18th Apr 2020, 6:06 AM
SUBHAM KAR CHOWDHURY
SUBHAM KAR CHOWDHURY - avatar
2 Answers
+ 1
Okay I got it. Thanks
18th Apr 2020, 6:19 AM
SUBHAM KAR CHOWDHURY
SUBHAM KAR CHOWDHURY - avatar
0
There is no calculation, this is only a lookup. get() checks if a key exists in the dictionary. If yes, it returns the value associated to the key. If not, the default value is returned from the second optional argument. In your example, the key 7 is not there in fib, therefore the result is 5.
18th Apr 2020, 6:17 AM
Tibor Santa
Tibor Santa - avatar