+ 1
I dont understand the output of this dictionary
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)) I don't get it, pls help.
2 Respostas
+ 3
Got it myself, thanks
just looked up the indexing.
If 7 can't be found in the dictionary the get method assigns a new given value for 7 which is in this case 5.
So the value for 4 is 3 and the new value for 7 is 5
--> 3+5=8
+ 2
get(key [, default]) returns value with the given key; if key doesn't exist it returns default (none by default)
fib.get(4, 0) returns 3
fib.get(7, 5) returns 5