+ 1
What's the output of this code..pls make me aware that what is p and 'p.get'?
p={1:5,2:5,3:6} print(p.get(8,4)+p.get(7,6))
6 Antworten
+ 4
Output of this code should be 4 and 6
get is a dictionary method ,it looks for the key in the dict and returns it value ,and if there is no key with that name then the value you gave in get method is returned as it's value ,
so here p.get(8,4)
looks for key 8 but since it is not there ,4 is returned as it's value
+ 3
because 8 and 7 not found in dict it returns 4 and 6
+ 2
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2451/
I hope this helps.
+ 2
Bhanu Tripathi "p" is a dictionary, whereas "p.get(x,y)" searches for the value of the key "x" in dictionary "p". If key "x" is not found it returns the "y".
+ 1
I can't get that...so I asked!!