+ 1
Dictionary Functions
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)) How this code give us the output is 8.?
2 Respostas
+ 3
the first get gets the value of key 4 ie 3, the second get looks for the key 7 value but since key 7 does not exist uses the default value you have set ie 5
5+3 = 8
+ 1
You used 2 arguments for Dictionary.get() in each case.
The get() method defaults to argument 2 if argument one cannot be found:
4 gets 3
0 skipped
7 gets None
5 returned (default)
3+5=8