+ 1
please explain why result is 8
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)) #thank you
3 odpowiedzi
+ 7
get 4 = 3 and get 7 = not found then use 5.
So it's 3 + 5 = 8
+ 1
The method fib.get() takes 2 parameters. The first will be the key to find and the second will be the default
value if the key cannot be found.
So basically:
dictionary.get(key_to_find, default_value)
+ 1
thank you both!