pairs = {1: "apple", "orange": [2, 3, 4], True: False, 12: "True", } print(pairs.get("orange")) print(pairs.get(7, 42))
3 Answers
New AnswerCan't understand print(pairs.get(7, 42))
5/25/2021 11:00:45 AM
prathiba singaravelu3 Answers
New Answerget() take one required argument (the key), and one optional argument (the value to return if the key was not found). so get(7,42) will return 42 as there is no 7 key in your pairs dict ^^
prathiba singaravelu 1 - get(key) // it will return None if key is not exist 2 - get(key, defaultValue) //it will return defaultValue if key is not exist. So where you are sure that if key not exist then default value should be return then you can use 2nd function.
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message