+ 3
Doubt related to dictionary
if x={1:2,2:3,3:4,4:6} .then what will be the value of print(x.get(5,4)) and how?
3 Respuestas
+ 5
https://www.tutorialspoint.com/JUMP_LINK__&&__python__&&__JUMP_LINK/dictionary_get.htm
x.get(a,b) will return the value associated with key 'a' of the dict variable 'x'. If key 'a' doesn't exist in the dictionary, then it will return the default value 'b'.
+ 4
thanks. understood it very well.
+ 3
x.get(5, 4)
The first argument passed (5) to the get method is the key to retrieve. The second number (4) is the default value if that key doesn't exist.
So, in this case 4 will be returned as there is no key 5 in the dictionary.