0

Please explain how 10 will be the output

p={1:5, 2:5, 3:6} print (p.get(8,4)+p.get(7,6)

9th Jan 2020, 4:43 AM
Navneet
Navneet - avatar
1 Answer
+ 3
get() has two parameters: first is the key you want to look up in the dictionary, second is the default value to use, when the key doesn't exist. Dictionary p has keys 1, 2 and 3 So 8 and 7 are not keys, hence the default value 4 and 6 are used in both cases.
9th Jan 2020, 4:46 AM
Tibor Santa
Tibor Santa - avatar