Help me pls about Dictionary function | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

24th Jul 2020, 9:30 AM
Paknonkit Kalayapichet
Paknonkit Kalayapichet - avatar
2 Answers
+ 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
24th Jul 2020, 9:34 AM
Bagon
Bagon - avatar
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
24th Jul 2020, 10:53 AM
uday kiran
uday kiran - avatar