0
What does this code means?
pairs = {1: "apple", "orange": [2, 3, 4], True: False, 12: "True", } print(pairs.get(5, 42))
4 ответов
+ 3
pairs is a dictionary, it associates every key to its value (key : value)
pairs.get(<key>, <alternative>) gives you the value associated to <key>, but if the key is not found it gives you <alternative>
+ 3
The number 42 *is* the alternative. So if the key does not exist the function returns the number 42.
+ 1
Thank you Angelo Simon Sauter
0
But, there is no alternative matching 42