+ 1
Help me pls about Dictionary function
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)) could you pls explain for me thank you
2 Antworten
+ 2
checks if the dictionary "fib" contains 4, since it does, assigns the value of 4:
fig.get(4, 0) = 3
checks if the dictionary "fib" contains 7, since it doesn't, assigns the secondary value(5):
fig.get(7, 5) = 5
3 + 5 = 8
0
Peak Kalayapichet
.get method checkes if key exists or not if exists return the value else returns default value specified.
Here the answer is 8