+ 4
what is pairs.get(12345,"not in dictionary") do ??
line1 pairs = {1: "apple", line2 "orange": [2, 3, 4], line3 True: False, line4 None: "True", line5 } line6 line7 print(pairs.get("orange")) line8 print(pairs.get(7)) line9 print(pairs.get(12345, "not in dictionary")) In this code i didn't understand line9 . what does this line do ?
3 Answers
+ 8
I got the answer
actually pairs.get return the value of the key.
here in line9
pairs.get first check whether 12345 is in the list or not.
here 12345 is not present in the list so it return the "not in dictionary" ( second argument)
so basically,
if the item is not present in the list .get(with single argument) usually return NONE but if .get(with two argument) it returns second argument.
+ 1
сам спросил и сам ответил?
+ 1
когда-нибудь это произойдет ... если у вас есть сомнения, и вдруг вы знаете ответ.
sometime it happens ... when you have a doubt and suddenly you know the answer.