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)) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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))

What is the result of this code? with detail description...

3rd Dec 2018, 9:51 AM
Sk.Basheera Sulthana
Sk.Basheera Sulthana - avatar
1 Answer
+ 2
In get() you have two parameters Actually the first one is the key and the second one is the value which is return when key is not present in the dictionary get(key, value to return if key is not present) fib.get(4,0) in this key 4 is present in the dictionary therefore value from dictionary is returned i.e. 3 fib.get(7,5) Key 7 is not present in the dictionary therefore 5 is returned So the output will be 3+5. = 8
3rd Dec 2018, 10:01 AM
Rishi Anand
Rishi Anand - avatar