Python Forum
Output explanation - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Output explanation (/thread-8154.html)



Output explanation - AmanTripathi - Feb-07-2018

I am unable to understand the output of this program. Can someone explain it to me?
stuff=dict()
print(stuff.get('candy',-1))



RE: Output explanation - buran - Feb-07-2018

stuff is a ductionary. dict is a data structure with key:values pairs. dict has .get(key, [default]) method. in this case get will look up for key 'candy' and will return respective value, but if there is no key 'candy' (as in this case) it will return the default value, which in this case is -1


RE: Output explanation - AmanTripathi - Feb-14-2018

Thank You :)