+ 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 ?

22nd Jan 2017, 4:29 PM
Mayank Singh Soni
Mayank Singh Soni - avatar
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.
22nd Jan 2017, 4:37 PM
Mayank Singh Soni
Mayank Singh Soni - avatar
+ 1
сам спросил и сам ответил?
22nd Jan 2017, 10:43 PM
Геймер Нещадный
Геймер Нещадный - avatar
+ 1
когда-нибудь это произойдет ... если у вас есть сомнения, и вдруг вы знаете ответ. sometime it happens ... when you have a doubt and suddenly you know the answer.
23rd Jan 2017, 2:11 AM
Mayank Singh Soni
Mayank Singh Soni - avatar