+ 2
pairs = {1: "apple", "orange": [2, 3, 4], True: False, None: "True", } print(pairs.get("orange")) print(pairs.get(1)) print(pairs.get(12345, "not in dictionary")) the output is ļ¼»2, 3, 4ļ¼½ False not in dictionary why is print(pairs.get(13345,"not in dictionary")) giving the output not in dictionary.pls I nid explanation
4 Answers
+ 6
liste.get(something, else)
if "something" is inside the list, you're asking the program to tell you what "something" is, however if it doesn't find "something", it will do whatever you put in the 'else' part. So in this case you're asking it to get [12345], but since it cannot find [12345] in the dictionary, it will print("not in dictionary")
+ 2
It will print not in dictionary ... nothing else ... try again
+ 1
if i got this right, you did not pushed the 12345 value in the dictionary before searching for it, so it is not there
0
What do you mean 12345 in the question?