+ 1

pairs = {1: "apple", "orange": [2, 3, 4], True: False, 12: "True", } print(pairs.get("orange")) print(pairs.get(7, 42))

Here what is the use of print((pairs.get(7,42))

12th Apr 2021, 4:43 PM
Sandeep
Sandeep - avatar
4 ответов
+ 3
Your program tell get() method to return a default value instead of None if key-value pair does not exist. Use to handle exception(NoneType)
12th Apr 2021, 6:03 PM
Apongpoh Gilbert
Apongpoh Gilbert - avatar
+ 2
Try get value by key 7 if value don't exist in dictionary return 42
12th Apr 2021, 4:50 PM
Илья Мирошник
Илья Мирошник - avatar
0
If u change 7 on 12 will return True
12th Apr 2021, 4:50 PM
Илья Мирошник
Илья Мирошник - avatar
0
TQ
12th Apr 2021, 5:04 PM
Sandeep
Sandeep - avatar